Browse Source

initial commit

master
Gator 2 years ago
committed by Ali Gator
commit
ee21955b2e
  1. 4
      .gitignore
  2. 3
      README.md
  3. 14
      requirements.txt
  4. 9
      src/common.py
  5. 25
      src/main.py
  6. 5
      src/processors/__init__.py
  7. 47
      src/processors/message.py

4
.gitignore

@ -0,0 +1,4 @@
config.yml
__pycache__
venv

3
README.md

@ -0,0 +1,3 @@
# Discordodrio
A simple Discord bot prototype that will parse and react to certain kind of messages and commands. It's a cheeky one.

14
requirements.txt

@ -0,0 +1,14 @@
aiohttp==3.6.2
async-timeout==3.0.1
attrs==19.3.0
chardet==3.0.4
discord.py==1.3.3
idna==2.9
idna-ssl==1.1.0
multidict==4.7.5
pkg-resources==0.0.0
PyYAML==5.3.1
pyyml==0.0.2
typing-extensions==3.7.4.2
websockets==8.1
yarl==1.4.2

9
src/common.py

@ -0,0 +1,9 @@
from yaml import load, FullLoader
def load_config():
with open('config.yml') as conf:
return load(conf, Loader=FullLoader)
config = load_config()

25
src/main.py

@ -0,0 +1,25 @@
import discord
import processors
from common import config
class Discordodrio(discord.Client):
def __init__(self):
super().__init__()
self.processors = [processor for processor in dir(processors) if processor.endswith('_processor')]
async def on_ready(self):
print(f'{self.user} has connected to Discord!')
async def on_message(self, message):
# don't respond to ourselves
if message.author == self.user:
return
for processor in self.processors:
if processor.startswith('msg'):
await getattr(processors, processor)(message)
CLIENT = Discordodrio()
CLIENT.run(config['token'])

5
src/processors/__init__.py

@ -0,0 +1,5 @@
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
from common import *
from .message import *

47
src/processors/message.py

@ -0,0 +1,47 @@
import random
from common import config
async def msg_pong_processor(msg):
if msg.content == 'ping':
await msg.channel.send('pong')
async def msg_self_processor(msg):
if bool(random.getrandbits(1)):
body = msg.content.lower()
if config["name"].lower() in body and \
"/attack" not in body:
answer = random.choice(config["self"])
await msg.channel.send(answer)
async def msg_talkback_processor(msg):
talkback = config['talkback']
for domain in talkback:
for j in domain['domain']['patterns']:
if j in msg.content.lower() and bool(random.getrandbits(1)):
answer = random.choice(domain["domain"]["answers"])
await msg.channel.send(answer)
async def msg_chapw_processor(msg):
if msg.content == "/chapw":
chapw = ['🧢 ', '👒', '⛑️', '🎩', '🎓']
amount = random.randint(1, 5)
bag = [random.choice(chapw) for i in range(0, amount)]
if random.randint(1, 10) == 9:
bag.append('💩')
answer = "Distribution de chapw %s" % " ".join(map(str, bag))
await msg.channel.send(answer)
async def msg_attack_processor(msg):
if bool(random.getrandbits(1)):
if "/attack " in msg.content:
answer = ""
if config["name"] in msg.content.lower():
answer = random.choice(config["attack"])
else:
answer = random.choice(config["attack_other"])
await msg.channel.send(answer)