print direct messages

This commit is contained in:
ddorn 2020-05-10 17:30:45 +02:00
parent 0f1bc903bf
commit 6815c33ea1
6 changed files with 47 additions and 22 deletions

5
bot.py
View File

@ -1,5 +1,4 @@
from src import bot
from src.constants import TOKEN
from src import start
if __name__ == "__main__":
bot.run(TOKEN)
start()

View File

@ -1 +1 @@
from src.tfjm_discord_bot import bot
from src.tfjm_discord_bot import start

View File

@ -2,7 +2,7 @@ import asyncio
from pprint import pprint
import discord
from discord import TextChannel, PermissionOverwrite, Message
from discord import TextChannel, PermissionOverwrite, Message, ChannelType
from discord.ext.commands import (
command,
has_role,
@ -16,6 +16,7 @@ from ptpython.repl import embed
from src.constants import *
from src.core import CustomBot
from src.utils import fg
COGS_SHORTCUTS = {
"bt": "src.base_tirage",
@ -203,6 +204,15 @@ class DevCog(Cog, name="Dev tools"):
await channel.delete_messages(to_delete)
await ctx.message.delete()
@Cog.listener()
async def on_message(self, msg: Message):
ch: TextChannel = msg.channel
if ch.type == ChannelType.private:
m = f"""{fg(msg.author.name)}: {msg.content}
MSG_ID: {fg(msg.id, 0x03A678)}
CHA_ID: {fg(msg.channel.id, 0x03A678)}"""
print(m)
def setup(bot: CustomBot):
bot.add_cog(DevCog(bot))

View File

@ -2,7 +2,7 @@ import asyncio
import sys
from importlib import reload
from discord import User, Message, Reaction, NotFound
from discord import User, Message, Reaction, NotFound, Forbidden
from discord.ext.commands import Bot
__all__ = ["CustomBot"]
@ -60,8 +60,12 @@ class CustomBot(Bot):
reaction, u = await bot.wait_for(
"reaction_add", check=check, timeout=timeout
)
the_msg = get(msgs, id=reaction.message.id)
await the_msg.delete()
the_msg: Message = get(msgs, id=reaction.message.id)
try:
await the_msg.delete()
except NotFound:
pass # message was deleted
msgs.remove(the_msg)
except asyncio.TimeoutError:
pass
@ -69,6 +73,6 @@ class CustomBot(Bot):
for m in msgs:
try:
await m.clear_reaction(Emoji.BIN)
except NotFound:
# Message or reaction deleted
except (NotFound, Forbidden):
# Message or reaction deleted / in dm channel
pass

View File

@ -5,7 +5,8 @@ from src.core import CustomBot
# We allow "! " to catch people that put a space in their commands.
# It must be in first otherwise "!" always match first and the space is not recognised
bot = CustomBot(("! ", "!"))
from src.utils import fg
# Global variable to hold the tirages.
# We *want* it to be global so we can reload the tirages cog without
@ -13,19 +14,23 @@ bot = CustomBot(("! ", "!"))
tirages = {}
@bot.event
async def on_ready():
print(f"{bot.user} has connected to Discord!")
def start():
bot = CustomBot(("! ", "!"))
@bot.event
async def on_ready():
print(f"{bot.user} has connected to Discord!")
bot.remove_command("help")
bot.load_extension("src.cogs.dev")
bot.load_extension("src.cogs.errors")
bot.load_extension("src.cogs.misc")
bot.load_extension("src.cogs.teams")
bot.load_extension("src.cogs.tirages")
bot.load_extension("src.utils")
bot.remove_command("help")
bot.load_extension("src.cogs.dev")
bot.load_extension("src.cogs.errors")
bot.load_extension("src.cogs.misc")
bot.load_extension("src.cogs.teams")
bot.load_extension("src.cogs.tirages")
bot.load_extension("src.utils")
bot.run(TOKEN)
if __name__ == "__main__":
bot.run(TOKEN)
start()

View File

@ -4,6 +4,13 @@ import psutil
from discord.ext.commands import Bot
def fg(text, color: int = 0xFFA500):
r = color >> 16
g = color >> 8 & 0xFF
b = color & 0xFF
return f"\033[38;2;{r};{g};{b}m{text}\033[m"
def french_join(l):
l = list(l)
start = ", ".join(l[:-1])