Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔥 Remove twitter from the rss plugin & rework a little bit how setup works internally #242

Merged
merged 5 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 38 additions & 14 deletions core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,32 @@
accept = ["y", "yes", "yeah", "ye"]
decline = ["n", "no", "nope", "nah"]


def ask_user(question: str, default: bool, emoji: str = "") -> bool:
if default:
question += " [Y/n]"
else:
question += " [y/N]"
if emoji:
emoji = emoji + " "
while True:
answer = input(f"{color.stop}{emoji}{color.fg.blue}{question}{color.stop}")
print(answer)
if not answer:
return default
if answer.lower() in accept:
return True
if answer.lower() in decline:
return False
print(f"{color.fg.red}Please answer by yes or no. "
f"You can also simply hit enter to use the default option.{color.stop}")


_global_config = {}

logger = setup_logger('config')


def check():
"Check basic requirements and start the setup script if something is missing"
if not os.path.isfile("config.yaml"):
Expand Down Expand Up @@ -77,6 +99,7 @@ def reload_config():
if not _global_config:
reload_config()


################
# Plugin Setup #
################
Expand All @@ -92,11 +115,12 @@ def setup_plugins():

plugin_setup = importlib.import_module("plugins." + plugin + ".setup")

choice = input(
f"\n{color.fg.blue}🔌 Do you want to configure {plugin} plugin? [Y/n]:{color.stop} "
opt_configure_plugin = ask_user(
f"Do you want to configure {plugin} plugin?",
default=True
)

if choice.lower() not in decline:
if opt_configure_plugin:
plugin_config = plugin_setup.run()
if plugin_config is not None:
_global_config.update({plugin: plugin_config})
Expand All @@ -116,11 +140,12 @@ def token_set(force_set=False):
False if not."""

if _global_config["bot"].get("token") is not None and not force_set:
choice = input(
f"\n🔑 {color.fg.blue}A token is already set."\
f"Do you want to edit it? [y/N]:{color.stop} "
opt_change_token = ask_user(
"A token is already set. Do you want to edit it?",
default=False,
emoji="🔑"
)
if choice.lower() not in accept:
if not opt_change_token:
return

# pylint: disable=line-too-long
Expand Down Expand Up @@ -150,7 +175,6 @@ def token_set(force_set=False):


def advanced_setup():

# Language

lang = "Baguette de fromage"
Expand Down Expand Up @@ -179,17 +203,17 @@ def advanced_setup():
while error:
error = False
choice = input(
f"\n{color.fg.blue}👑 Bot admins"\
f"(User ID separated with comma. Let empty to ignore):{color.stop} "
f"\n{color.fg.blue}👑 Bot admins" \
f"(User ID separated with comma. Let empty to ignore):{color.stop} "
)
if choice != "":
admins = choice.replace(" ", "").split(",")
try:
_global_config["bot"]["admins"] = [int(admin_id) for admin_id in admins]
except ValueError:
print(
f"{color.fg.red}👑 Invalid entry. Only user ID (integers),"\
f"comma and space are expected.{color.stop}"
f"{color.fg.red}👑 Invalid entry. Only user ID (integers)," \
f"comma and space are expected.{color.stop}"
)
error = True

Expand All @@ -207,8 +231,8 @@ def advanced_setup():
_global_config["bot"]["error_channels"] = channel
except ValueError:
print(
f"{color.fg.red}🤕 Invalid entry. Only channel ID (integers) are expected."\
f"{color.stop}"
f"{color.fg.red}🤕 Invalid entry. Only channel ID (integers) are expected." \
f"{color.stop}"
)
error = True

Expand Down
7 changes: 1 addition & 6 deletions plugins/rss/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,4 @@
# utiliser, modifier et/ou redistribuer ce programme sous les conditions
# de la licence CeCILL diffusée sur le site "http://www.cecill.info".

twitter:
consumer_key: null
consumer_secret: null
access_token_key: null
access_token_secret: null
rss_loop_enabled: true
rss_loop_enabled: true
4 changes: 2 additions & 2 deletions plugins/rss/docs/user_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ de la licence CeCILL diffusée sur le site "http://www.cecill.info".

# 📰 RSS

Gipsy offers you the possibility to follow different content sources, from social networks like Youtube or Twitter to simple blogs equipped with an RSS feed system.
Gipsy offers you the possibility to follow different content sources, from social networks like Youtube or Twitch to simple blogs equipped with an RSS feed system.

## Add or remove a feed

Expand Down Expand Up @@ -65,7 +65,7 @@ Modifies the text of the feed. Several variables can be used in the text:
* `{channel}` : the name of the channel
* `{date}` : the date of publication of the post (UTC)
* `{link}` or `{url}` : the link to the post
* `{logo}` : an emoji representing the type of post (web, Twitter, YouTube...)
* `{logo}` : an emoji representing the type of post (web, YouTube, Twitch...)
* `{mentions}` : the list of roles mentioned
* `{title}` : the title of the post

Expand Down
9 changes: 2 additions & 7 deletions plugins/rss/langs/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

en:
rss:
change-txt: "The current message contain \n```\n{text}\n```\nPlease enter the text to be used in a new post. You can use several variables, there is the list:\n- `{author}`: post author\n- `{channel}`: channel name (usually the same as the author)\n- `{date}`: post date (UTC)\n- `{link}` or `{url}`: a link to the post\n- `{logo}`: an emoji representing the type of post (web, Twitter, YouTube...)\n- `{mentions}`: list of mentionned roles\n- `{title}`: post title"
change-txt: "The current message contain \n```\n{text}\n```\nPlease enter the text to be used in a new post. You can use several variables, there is the list:\n- `{author}`: post author\n- `{channel}`: channel name (usually the same as the author)\n- `{date}`: post date (UTC)\n- `{link}` or `{url}`: a link to the post\n- `{logo}`: an emoji representing the type of post (web, Twitch, YouTube...)\n- `{mentions}`: list of mentionned roles\n- `{title}`: post title"
choose-delete: "Chose a feed to delete"
choose-mentions-1: "Chose a feed to edit"
choose-roles: "Wich role do you want to mention?"
Expand All @@ -31,7 +31,6 @@ en:
no-feed2: "This server has no rss feeds!"
no-roles: "No roles have been configured yet."
not-a-role: "This role cannot be found. Try again."
wrong-token: "Invalid twitter API token."
nothing: "I couldn't find anything on this search :confused:"
research-timeout: "The web page took too long to respond, I had to abort the process :eyes:"
roles-0: "This feed has been modified to mention roles {}"
Expand All @@ -40,10 +39,6 @@ en:
success-add: "The rss feed of type '{}' with the link <{}> has been added to the {} channel!"
text-success: "The text of the feed n°{} has been modified! New text: \n```\n{}\n```"
too-long: "You waited too long, sorry :hourglass:"
tw: "Twitter"
tw-default-flow: "{logo} | New tweet of {author}! ({date})\n\n{title}\n\nLink: {link}\n\n{mentions}"
tw-form-last: "{logo} | Here is the latest tweet from {author}:\nWritten on {date}\n\n{title}\n\nLink: {url}\n"
tw-help: "To search for a twitter channel, you have to enter the id of this channel. You will find it at the end of the url of the channel, it usually corresponds to the name of the user. For example, for *https://twitter.com/Gunivers_*, you have to enter `Gunivers_`"
twitch: "Twitch"
twitch-default-flow: "{logo} | {author} is live! ({date})\n\n{title}\n\nLink: {link}\n\n{mentions}"
twitch-form-last: "{logo} | Here is the last video of {author}:\n{title}\nPublished on {date}\nLink: {url}\n"
Expand All @@ -59,4 +54,4 @@ en:
yt: "YouTube"
yt-default-flow: "{logo} | New vidéo from {author}: **{title}**\nPublished on {date}\nLink: {link}\n{mentions}"
yt-form-last: "{logo} | ere is the last video of {author}:\n{title}\nPublished on {date}\nLink: {url}"
yt-help: "To search for a youtube channel, you need to enter the id of this channel. You will find it at the end of the url of the channel, it can be either the name or a random sequence of characters"
yt-help: "To search for a youtube channel, you need to enter the id of this channel. You will find it at the end of the url of the channel, it can be either the name or a random sequence of characters"
9 changes: 2 additions & 7 deletions plugins/rss/langs/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

fr:
rss:
change-txt: "Le message actuel contient \n```\n{text}\n```\nVeuillez entrer le texte à utiliser lors d'un nouveau post. Vous pouvez utiliser plusieurs variables, dont voici la liste :\n- `{author}` : l'auteur du post\n- `{channel}` : le nom de la chaîne (généralement le même que l'auteur)\n- `{date}` : la date du post (UTC)\n- `{link}` ou `{url}` : un lien vers le post\n- `{logo}` : un emoji représentant le type de post (web, Twitter, YouTube...)\n- `{mentions}` : la liste des rôles mentionnés\n- `{title}` : le titre du post"
change-txt: "Le message actuel contient \n```\n{text}\n```\nVeuillez entrer le texte à utiliser lors d'un nouveau post. Vous pouvez utiliser plusieurs variables, dont voici la liste :\n- `{author}` : l'auteur du post\n- `{channel}` : le nom de la chaîne (généralement le même que l'auteur)\n- `{date}` : la date du post (UTC)\n- `{link}` ou `{url}` : un lien vers le post\n- `{logo}` : un emoji représentant le type de post (web, Twitch, YouTube...)\n- `{mentions}` : la liste des rôles mentionnés\n- `{title}` : le titre du post"
choose-delete: "Veuillez choisir le flux à supprimer"
choose-mentions-1: "Veuillez choisir le flux à modifier"
choose-roles: "Quels seront les rôles à mentionner ?"
Expand All @@ -31,7 +31,6 @@ fr:
no-feed2: "Ce serveur ne possède aucun flux rss !"
no-roles: "Aucun rôle n'a été configuré pour l'instant."
not-a-role: "Ce rôle est introuvable. Réessayez :"
wrong-token: "Le token d'API Twitter n'est pas bon"
nothing: "Je n'ai rien trouvé sur cette recherche :confused:"
research-timeout: "La page web a mis trop de temps à répondre, j'ai dû interrompre le processus :eyes:"
roles-0: "Ce flux a bien été modifié pour mentionner les rôles {}"
Expand All @@ -40,10 +39,6 @@ fr:
success-add: "Le flux rss de type '{}' avec le lien <{}> a bien été ajouté dans le salon {} !"
text-success: "Le texte du flux n°{} a bien été modifié ! Nouveau texte : \n```\n{}\n```"
too-long: "Vous avez trop attendu, désolé :hourglass:"
tw: "Twitter"
tw-default-flow: "{logo} | Nouveau tweet de {author} ! ({date})\n\n{title}\n\nLien : {link}\n\n{mentions}"
tw-form-last: "{logo} | Voici le dernier tweet de {author}:\nÉcrit le {date}\n\n{title}\n\nLien : {url}\n"
tw-help: "Pour rechercher une chaîne twitter, vous devez entrer l'identifiant de cette chaîne. Vous la trouverez à la fin de l'url de la chaîne, elle correspond généralement au nom de l'utilisateur. Par exemple, pour *https://twitter.com/Gunivers_*, il faut rentrer `Gunivers_`"
twitch: "Twitch"
twitch-default-flow: "{logo} | Nouveau live de {author} ! ({date})\n\n{title}\n\nLien : {link}\n\n{mentions}"
twitch-form-last: "{logo} | Voici la dernière vidéo de {author}:\n{title}\nPubliée le {date}\nLien : {url}\n"
Expand All @@ -59,4 +54,4 @@ fr:
yt: "YouTube"
yt-default-flow: "{logo} | Nouvelle vidéo de {author} : **{title}**\nPubliée le {date}\nLien : {link}\n{mentions}"
yt-form-last: "{logo} | Voici la dernière vidéo de {author}:\n{title}\nPubliée le {date}\nLien : {url}"
yt-help: "Pour rechercher une chaîne youtube, vous devez entrer l'identifiant de cette chaîne. Vous la trouverez à la fin de l'url de la chaine, elle peut être soit le nom, soit une suite de caractères aléatoires"
yt-help: "Pour rechercher une chaîne youtube, vous devez entrer l'identifiant de cette chaîne. Vous la trouverez à la fin de l'url de la chaine, elle peut être soit le nom, soit une suite de caractères aléatoires"
Loading