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

Première programme corrigé #66

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/codacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
# Adjust severity of non-security issues
gh-code-scanning-compat: true
# Force 0 exit code to allow SARIF file generation
# This will handover control about PR rejection to the GitHub side
# This will hand over control about PR rejection to the GitHub side
max-allowed-issues: 2147483647

# Upload the SARIF file generated in the previous step
Expand Down
42 changes: 0 additions & 42 deletions Discord-Bot-main/Bot/DebugBot.py

This file was deleted.

61 changes: 0 additions & 61 deletions Discord-Bot-main/Bot/UR-Bot.py

This file was deleted.

41 changes: 41 additions & 0 deletions Discord-Bot-main/Bot/debug_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from importlib import reload
import event
import types


# Déclaration d'un décorateur à fonction (@update_module(module_name))
def update_module(module):
def __update__(func):
# Recherche du module pour voir s'il est déjà chargé ; si ce n'est pas le cas :
# il importe dynamiquement et ensuite, la fonction 'reload' recharge le module.
async def callback(*args, **kwargs):
reload(__import__(module, globals(), locals(), [],
0))
return await func(*args, **kwargs)
return callback
return __update__


def update_all_modules(func):
async def __update__(*args, **kwargs):
for name, val in globals().items():
if isinstance(val, types.ModuleType):
print(val.__name__)
reload(__import__(val.__name__, globals(), locals(), [], 0))

reload(__import__("DebugBot", globals(), locals(), [], 0))

return await func(*args, **kwargs)
return __update__


async def debug_on_message(*args, **kwargs):
return await event.on_message(*args, **kwargs)


async def debug_on_prez(*args, **kwargs):
return await event.on_prez(*args, **kwargs)


async def debug_on_help(*args, **kwargs):
return await event.on_help(*args, **kwargs)
1 change: 0 additions & 1 deletion Discord-Bot-main/Bot/description.txt

This file was deleted.

174 changes: 85 additions & 89 deletions Discord-Bot-main/Bot/event.py
Original file line number Diff line number Diff line change
@@ -1,132 +1,128 @@

import asyncio
import discord

BOT_PREFIX = "$"


HELP_DATA = {
"About":
{
"cmd_0":
{
"cmd": "credit",
"help": "Affiche les crédits"
},

"cmd_1":
{
"cmd": "version",
"help": "Affiche les numéros de version"
},
},

"General":
{
"cmd_0":
{
"cmd": "cancel",
"help": "Annule l'action en cours"
},

"cmd_1":
{
"cmd": "done",
"help": "Confirme l'action en cours"
},

"cmd_2":
{
"cmd": "edit",
"help": "Édite un message"
},

"cmd_3":
help_data = {
"About":
{
"cmd": "lang",
"help": "Change la langue de l'utilisateur"
"cmd_0":
{
"cmd": "credit",
"help": "Affiche les crédits"
},
"cmd_1":
{
"cmd": "version",
"help": "Affiche les numéros de version"
},
},
},

"Planning":
{
"cmd_0":
"General":
{
"cmd": "cal",
"help": "Permet d'accéder au calendrier"
"cmd_0":
{
"cmd": "cancel",
"help": "Annule l'action en cours"
},
"cmd_1":
{
"cmd": "done",
"help": "Confirme l'action en cours"
},
"cmd_2":
{
"cmd": "edit",
"help": "Édite un message"
},
"cmd_3":
{
"cmd": "lang",
"help": "Change la langue de l'utilisateur"
},
},

"cmd_1":
{
"cmd": "jdr",
"help": "Envoie un lien pour créer une partie"
},

"cmd_2":
"Planning":
{
"cmd": "site",
"help": "Permet d'accéder au calendrier"
"cmd_0":
{
"cmd": "cal",
"help": "Permet d'accéder au calendrier"
},
"cmd_1":
{
"cmd": "jdr",
"help": "Envoie un lien pour créer une partie"
},
"cmd_2":
{
"cmd": "site",
"help": "Permet d'accéder au calendrier"
},
},

},

"Presentation":
{
"cmd_0":
"Presentation":
{
"cmd": "prez",
"help": "Envoie un lien pour se présenter"
"cmd_0":
{
"cmd": "prez",
"help": "Envoie un lien pour se présenter"
},
},
},

"No Category":
{
"cmd_0":
{
"cmd": "help",
"help": "Affiche ce message"
},
}

"cmd_0":
{
"cmd": "help",
"help": "Affiche ce message"
},
}
}


def GetMaxStrSizeInArray(array:dict,callback=None):
_size=0
def GetMaxStrSizeInArray(array: dict, callback=None):
_size = 0
for cmd in array:
_r = callback(cmd)
if(_r > _size):
_size = _r
if _r > _size:
_size = _r
return _size


async def on_message(event,*args,**kwargs):

async def on_message(event, *args):
if event.content.startswith('hi'):
await event.channel.send(f'Hello! Mis a jour : {args}')


async def on_prez(event,*args,**kwargs):
embed = discord.Embed(url="http://presentation.unionrolistes.fr/?webhook=https://discord.com/api/webhooks/875068900612665396/DJusy0eGs9Xyx2os-dodBVfWia2fbhfBzfmnDM9g-30ozoFYAuZBHVXaD9TKaC1wwBwg", description="⬆️ Here is the link to create your presentation.", title="Union Roliste - Presentation", color= 0x0CC1EE)
async def on_prez(event):
embed = discord.Embed(
url="http://presentation.unionrolistes.fr/?webhook=https://discord.com/api/webhooks/875068900612665396/DJusy0eGs9Xyx2os-dodBVfWia2fbhfBzfmnDM9g-30ozoFYAuZBHVXaD9TKaC1wwBwg",
description="⬆️ Here is the link to create your presentation.", title="Union Roliste - Presentation",
color=0x0CC1EE)
embed.set_author(name=event.author.display_name, icon_url=event.author.avatar_url)

DATA = ["**:pen_ballpoint: Nom\n**","**:pen_ballpoint: Prenom\n**",":round_pushpin: **Address\n**",":telephone: **N° Telephone\n**", ":postbox: **Code postal\n**","**:computer: Support (Windows / Linux / Mac)\n**","**Expérience en programmation\n**"]
# DATA = ["**:pen_ballpoint: Nom\n**", "**:pen_ballpoint: Prenom\n**", ":round_pushpin: **Address\n**",
# ":telephone: **N° Telephone\n**", ":postbox: **Code postal\n**",
# "**:computer: Support (Windows / Linux / Mac)\n**", "**Expérience en programmation\n**"]
# La variable n'est jamais utilisée. Ceci dit, je la laisse en commentaire, au cas où un futur dev l'utiliserait.

embed.add_field(name="**\n**", value="**───────────────────────────────**", inline=False)

embed.set_footer(text="Union Roliste dev presentation.", icon_url="https://avatars.githubusercontent.com/u/62179928?s=200&v=4")
embed.set_footer(text="Union Roliste dev presentation.",
icon_url="https://avatars.githubusercontent.com/u/62179928?s=200&v=4")

embed.set_thumbnail(url="https://avatars.githubusercontent.com/u/62179928?s=200&v=4")

await event.author.send(embed=embed) # envoie un message de presentation privée à l'auteur qui a fait a commandes
await event.author.send(embed=embed) # envoie un message de presentation privée à l'auteur qui a fait a commandes


async def on_help(event):
embed = discord.Embed(title="Assistance UR-Bot", color=0x000000)
embed.set_author(name="Union des Rôlistes", icon_url="https://cdn.discordapp.com/avatars/1040275175687606372/33d5a8782c1d658caeeae59799e722b0.webp?size=32")
embed.set_author(name="Union des Rôlistes",
icon_url="https://cdn.discordapp.com/avatars/1040275175687606372/33d5a8782c1d658caeeae59799e722b0.webp?size=32")
embed.set_footer(text="Soutenez le JDR, Soutenez l'UR !")
embed.set_thumbnail(url="https://avatars.githubusercontent.com/u/62179928?s=200&v=4") # Initialiser le logo de l'UR en haut à droite
embed.set_thumbnail(
url="https://avatars.githubusercontent.com/u/62179928?s=200&v=4") # Initialiser le logo de l'UR en haut à droite

first_category = True # Voir le bloc if/else pour comprendre
for category, commands in HELP_DATA.items():
for category, commands in help_data.items():
# Si l'écriture de l'embed n'en est pas à sa première catégorie (About, General, Présentation, etc.), alors :
if not first_category:
# Ajouter une ligne qui sépare les catégories entre-elles.
Expand Down
Loading
Loading