forked from GreigHuth/moobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
moobot.py
191 lines (146 loc) · 5.54 KB
/
moobot.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
"""moobot
moobot is a shitty discord bot that helps people
pay their respects
"""
import logging
import sqlite3
import re
import discord
from discord.ext import commands
import config
import commands as command
logging.basicConfig(level=logging.INFO)
class Respect:
"""Press f to pay respects."""
def __init__(self, bot):
self.bot = bot
self.conn = conn
self.c = c
@commands.command(pass_context=True,
aliases=['F', 'x', 'X', 'Blep', 'blep'])
async def f(self, ctx):
"""pays respects"""
await command.f(self, ctx)
@commands.command(pass_context=True,
aliases=['Respect', 'r', 'actualrespect', 'realrespect'])
async def respect(self, ctx):
"""displays how much respect the user has"""
await command.respect(self, ctx)
@commands.command(pass_context=True)
async def top(self, ctx):
"""displays the people with the most respect"""
await command.top_respect(self, ctx)
class Harambe:
"""Harambe related commands.
Harambe on moobot works as follows:
1. work out how long since harambe was last mentioned
2. * if it's more than one day, display the difference in days+
* if it's exactly one day, display and update the chain variable+
* if it's less than one day, do nothing
3. except in the third case, reset the last mentioned data
4. update the counter
"""
def __init__(self, bot):
self.bot = bot
self.conn = conn
self.c = c
@commands.command(pass_context=True)
async def harambe(self, ctx):
"""resets the harambe counter"""
await command.harambe(self, ctx)
class WithRice:
"""A retired meme"""
def __init__(self, bot):
self.bot = bot
self.conn = conn
self.c = c
@commands.command(pass_context=True)
async def with_rice(self, ctx):
"""spicy memes return to moobot? nah"""
await commands.with_rice
class OneTwoTwoTwoThreeFourFive:
"""just don't ask"""
def __init__(self, bot):
self.bot = bot
@commands.command(pass_context=True)
async def one_two_two_two_three_four_five(self, ctx):
"""just don't ask"""
await command.one_two_two_two_three_four_five(self, ctx)
class CopyPasta:
"""don't know why I made this"""
def __init__(self, bot):
self.bot = bot
@commands.command(pass_context=True)
async def copy_pasta(self, ctx):
"""memify your text"""
# connect to the DB
conn = sqlite3.connect(config.database_file)
c = conn.cursor()
# initialise if necessary
c.execute('''create table if not exists respect
(user text, f integer) ''')
# user is the discord user id
# f is an integer with the number of times a user has paid respects
c.execute('''create table if not exists harambe
(server text, last text,
number integer, chain integer, max integer)''')
# channel is a discord channel id
# last is a datetime containing the last noted harambe reference
c.execute('''create table if not exists ratings
(thing text, rater text,
without integer, with integer)''')
bot = commands.Bot(command_prefix=commands.when_mentioned,
description='a shitty discord bot for respect and harambe')
bot.add_cog(Harambe(bot))
bot.add_cog(Respect(bot))
bot.add_cog(OneTwoTwoTwoThreeFourFive(bot))
bot.add_cog(WithRice(bot))
harambe = bot.get_cog('Harambe')
respect = bot.get_cog('Respect')
one_two = bot.get_cog('OneTwoTwoTwoThreeFourFive')
with_rice = bot.get_cog('WithRice')
password_matcher = re.compile('122+345') # 1222*345
with_rice_matcher = re.compile('.*[0-9]+/10.*')
logging.log(msg='cogs: %s %s %s %s' % (harambe, respect, one_two, with_rice),
level=logging.INFO)
# helper function
def context_factory(message, bot):
return commands.Context(message = message,
bot = bot,
args = [],
kwargs = {},
prefix = '',
command = message.content)
@bot.event
async def on_ready():
logging.log(msg='%s - %s' % (bot.user.name, bot.user.id),
level=logging.INFO)
logging.log(msg='playing: %s' % config.status_message,
level=logging.INFO)
await bot.change_presence(
game=discord.Game(name='%s' % config.status_message))
@bot.event
async def on_message(message):
# print(message.content.lower())
# don't trigger on own messages
if message.author.id == bot.user.id:
pass
elif message.content.lower() in ['f', 'x', 'blep']:
await command.f(respect, context_factory(message, respect))
elif message.content.lower() in ['respect', 'actualrespect', 'realrespect']:
await command.respect(respect, context_factory(message, respect))
elif message.content.lower() == 'top':
await command.top_respect(respect, context_factory(message, respect))
elif 'harambe' in message.content.lower():
await command.harambe(harambe, context_factory(message, harambe))
elif with_rice_matcher.match(message.content):
await command.with_rice(WithRice, context_factory(message, with_rice))
elif password_matcher.match(message.content):
await command.one_two_two_two_three_four_five(one_two,
context_factory(message, one_two))
await bot.process_commands(message)
if config.moobot_login['discord_token'] is not None:
bot.run(config.moobot_login['discord_token'])
else:
bot.run(config.moobot_login['email'],
config.moobot_login['password'])