failed try with sniper channel
This commit is contained in:
parent
53088fdaaa
commit
cf0d585013
30
main.py
30
main.py
@ -1,5 +1,6 @@
|
||||
from typing import Final
|
||||
import os
|
||||
import re
|
||||
|
||||
from discord.ext import commands
|
||||
from dotenv import load_dotenv
|
||||
@ -7,12 +8,23 @@ from discord import Intents, Client, Message, User, Guild
|
||||
|
||||
load_dotenv()
|
||||
TOKEN: Final[str] = os.getenv('DISCORD_TOKEN')
|
||||
REGEXP: Final[str] = '<[a-z:0-9]*><[a-z:0-9]*>(.*)\(http.*\)(\(.*\)) `(.*)` (through|by) <[a-z:0-9]*><[a-z:0-9]*>(.*)\(http.*\)(\(.*\))'
|
||||
|
||||
intents: Intents = Intents.default()
|
||||
intents.message_content = True # NOQA
|
||||
client: Client = Client(intents=intents)
|
||||
|
||||
|
||||
def clean_message(message: str) -> str:
|
||||
print(f'received {message}')
|
||||
m = re.search(REGEXP, message)
|
||||
if m and len(m.groups()) == 6:
|
||||
r = m.group(1) + m.group(2) + m.group(3) + m.group(5) + m.group(6)
|
||||
print(f'cleaned into {r}')
|
||||
return r
|
||||
print('unable to clean the message')
|
||||
|
||||
|
||||
@client.event
|
||||
async def on_ready() -> None:
|
||||
print('Sentinel ready !', flush=True)
|
||||
@ -22,25 +34,29 @@ async def on_ready() -> None:
|
||||
async def on_message(message: Message) -> None:
|
||||
|
||||
user_message: str = str(message.content)
|
||||
if not user_message:
|
||||
for embed in message.embeds:
|
||||
print(embed.description)
|
||||
# user_message = clean_message(embed.description)
|
||||
|
||||
if message.author == client.user:
|
||||
# to avoid infinite loop, let's not answer to messages we (client.user) emit ourselves
|
||||
print('no answer to our own message', flush=True)
|
||||
return
|
||||
if not user_message:
|
||||
print('no message to send', flush=True)
|
||||
print('message is empty or not parseable, ignoring', flush=True)
|
||||
return
|
||||
if message.channel.id != 1218104927336009788:
|
||||
print('channel not monitored', flush=True)
|
||||
return
|
||||
if 'Kriss' not in user_message:
|
||||
print('message not implying "Kriss"', flush=True)
|
||||
print('message received on a not monitored channel, ignoring', flush=True)
|
||||
return
|
||||
# if 'Kriss' not in user_message:
|
||||
# print('message not implying "Kriss"', flush=True)
|
||||
# return
|
||||
|
||||
print(f'[{str(message.channel)}] {str(message.author)}: "{user_message}"', flush=True)
|
||||
print(f'{str(message.author)}: "{user_message}"', flush=True)
|
||||
|
||||
try:
|
||||
channel = client.get_channel(1256995195954790410)
|
||||
channel = client.get_channel(1218138955137155193)
|
||||
await channel.send(user_message)
|
||||
except Exception as e:
|
||||
print(e, flush=True)
|
||||
|
Loading…
Reference in New Issue
Block a user