-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmaddie.py
96 lines (81 loc) · 3.22 KB
/
maddie.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# bot.py
import os
import discord
import json
import logging
from dotenv import load_dotenv
from moves import get_moves
from parse import mad_parse
from command_handler import plain_command_handler, embed_command_handler
from config_interactions import get_dicedisplay
from discord_slash import SlashCommand
from discord_slash.utils.manage_commands import create_choice, create_option
from discord.ext import commands
logger = logging.getLogger('discord')
logger.setLevel(logging.INFO) #set logging level to INFO, DEBUG if we want the full dump
handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='a') #open log file in append mode
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
logger.info (TOKEN)
client = discord.Client()
@client.event
async def on_ready():
logger.info(f'{client.user} has connected to Discord!')
servers = list(client.guilds)
logger.info("Connected on "+str(len(client.guilds))+" servers:")
for x in range(len(servers)):
logger.info(' ' + servers[x-1].name)
def msg_log_line(message):
if message.guild is not None:
return message.guild.name + "|" + message.channel.name + "|" + message.author.name + "|" + message.content
else:
return "[Direct Message]" + "|" + message.author.name + "|" + message.content
#Listen for messages
@client.event
async def on_message(message):
if message.author == client.user:
return
# handle help and all of the playbook interactions
if message.content.startswith("!"):
response = plain_command_handler(message)
if response:
log_line = msg_log_line(message)
logger.info(log_line)
await message.channel.send(response)
return
response = embed_command_handler(message)
if response:
log_line = msg_log_line(message)
logger.info(log_line)
await message.channel.send(embed=response)
return
#answer a call for help
if message.content.startswith("!help"):
log_line = msg_log_line(message)
logger.info(log_line)
help_file = open("help", "r")
response = help_file.read()
await message.author.send(response)
await message.channel.send("I have sent help to your PMs.")
#list moves#
if message.content.startswith("!"):
move_list = get_moves(message)
if move_list:
await message.channel.send(move_list)
#remember generic ! should always be last in the tree#
else:
log_line = msg_log_line(message)
logger.info(log_line)
response = mad_parse(message)
if response:
logger.info(response)
(response, addendum) = response
# if addendum is not None: ##testing if going first made a difference
# await message.channel.send(content = addendum)
await message.channel.send(embed=response)
if addendum is not None:
await message.channel.send(content = addendum)
else : logger.info('no match found for '+message.content)
client.run(TOKEN)