Prefixing channel names

This commit is contained in:
Simon Junod
2023-10-31 00:17:09 +01:00
parent 91f47d1d80
commit f63de6586b
3 changed files with 52 additions and 6 deletions

16
poetry.lock generated
View File

@@ -277,6 +277,20 @@ files = [
{file = "charset_normalizer-3.2.0-py3-none-any.whl", hash = "sha256:8e098148dd37b4ce3baca71fb394c81dc5d9c7728c95df695d2dca218edf40e6"}, {file = "charset_normalizer-3.2.0-py3-none-any.whl", hash = "sha256:8e098148dd37b4ce3baca71fb394c81dc5d9c7728c95df695d2dca218edf40e6"},
] ]
[[package]]
name = "emoji"
version = "2.8.0"
description = "Emoji for Python"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
files = [
{file = "emoji-2.8.0-py2.py3-none-any.whl", hash = "sha256:a8468fd836b7ecb6d1eac054c9a591701ce0ccd6c6f7779ad71b66f76664df90"},
{file = "emoji-2.8.0.tar.gz", hash = "sha256:8d8b5dec3c507444b58890e598fc895fcec022b3f5acb49497c6ccc5208b8b00"},
]
[package.extras]
dev = ["coverage", "coveralls", "pytest"]
[[package]] [[package]]
name = "frozenlist" name = "frozenlist"
version = "1.4.0" version = "1.4.0"
@@ -621,4 +635,4 @@ multidict = ">=4.0"
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.10" python-versions = "^3.10"
content-hash = "5b48792862b482a79e3aa47c0bcbd4b0328067319f200a0b9e18135f59185532" content-hash = "9242538fd34a7c862185523b7db15cde94069c1411cbda62d67ae4e196b5ed27"

View File

@@ -11,6 +11,7 @@ unidecode = "^1.3.6"
requests = "^2.31.0" requests = "^2.31.0"
bs4 = "^0.0.1" bs4 = "^0.0.1"
nextcord = "^2.5.0" nextcord = "^2.5.0"
emoji = "^2.8.0"
[build-system] [build-system]

41
run.py
View File

@@ -1,9 +1,10 @@
import sys
import nextcord import nextcord
import hashlib import hashlib
import re import re
import asyncio import asyncio
import random import random
import base64
import emoji
from datetime import datetime from datetime import datetime
import cambot.codenames as codenames import cambot.codenames as codenames
import cambot.wordle as wordle import cambot.wordle as wordle
@@ -70,28 +71,58 @@ async def on_message(message):
games_entered = [codenames_game for codenames_game in codenames_games.values() if codenames_game.get_player(message.author)] games_entered = [codenames_game for codenames_game in codenames_games.values() if codenames_game.get_player(message.author)]
# Admin commands # Admin commands
print(message.author.name)
if message.author.name == "biganon": if message.author.name == "biganon":
if regex := re.search(r"^[sS]ay ([0-9]+) (.*)$", content): if regex := re.search(r"^[sS]ay ([0-9]+) (.*)$", content):
channel_id = int(regex.group(1)) channel_id = int(regex.group(1))
to_say = regex.group(2) to_say = regex.group(2)
await bot.get_channel(channel_id).send(to_say) await bot.get_channel(channel_id).send(to_say)
if regex := re.search(r"^wordle targets?$", content_lowercase): if regex := re.search(r"^[wW]ordle targets?$", content_lowercase):
output = "" output = ""
for wordle_game in wordle_games.values(): for wordle_game in wordle_games.values():
output += f"{wordle_game.channel.guild} > {wordle_game.channel.name} : {wordle_game.target}\n" output += f"{wordle_game.channel.guild} > {wordle_game.channel.name} : {wordle_game.target}\n"
await message.author.send(output) await message.author.send(output)
if regex := re.search(r"^wordle reset ([0-9]+)$", content_lowercase): if regex := re.search(r"^[wW]ordle reset ([0-9]+)$", content_lowercase):
channel_id = int(regex.group(1)) channel_id = int(regex.group(1))
await wordle_games[channel_id].reset() await wordle_games[channel_id].reset()
if regex := re.search(r"^ephemeris$", content_lowercase): if regex := re.search(r"^[eE]phemeris$", content_lowercase):
embed = ephemeris.digest() embed = ephemeris.digest()
for channel_id in EPHEMERIS_CHANNEL_IDS: for channel_id in EPHEMERIS_CHANNEL_IDS:
await bot.get_channel(channel_id).send(embed=embed) await bot.get_channel(channel_id).send(embed=embed)
if regex := re.search(r"^[dD]ump ([0-9]+)$", content):
guild_id = int(regex.group(1))
guild = bot.get_guild(guild_id)
string = ",".join(channel.name for channel in guild.text_channels)
b64 = base64.b64encode(string.encode("utf-8")).decode()
await message.author.send(string)
await message.author.send(b64)
if regex := re.search(r"[lL]oad ([0-9]+) (.*)$", content):
guild_id = int(regex.group(1))
guild = bot.get_guild(guild_id)
b64 = regex.group(2)
string = base64.b64decode(b64.encode("utf-8")).decode()
names = string.split(",")
if len(names) != len(guild.text_channels):
await message.author.send(f"Erreur : {len(names)} noms fournis, mais {len(guild.text_channels)} canaux trouvés")
return
for idx, channel in enumerate(guild.text_channels):
await channel.edit(name=names[idx])
if regex := re.search(r"[pP]refix ([0-9]+) (.*)$", content):
guild_id = int(regex.group(1))
guild = bot.get_guild(guild_id)
prefix = regex.group(2)
for channel in guild.text_channels:
if emoji.is_emoji(channel.name[0]):
unprefixed = channel.name[1:]
else:
unprefixed = channel.name
await channel.edit(name=prefix+unprefixed)
# Codenames whispers # Codenames whispers
if len(games_entered) == 1: if len(games_entered) == 1:
await codenames.process_whisper(games_entered[0], message) await codenames.process_whisper(games_entered[0], message)