-
Notifications
You must be signed in to change notification settings - Fork 3
/
commands.py
170 lines (125 loc) · 5.42 KB
/
commands.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
"""holds moobots commands"""
import asyncio
import datetime
import config
async def harambe(cls_, ctx):
"""harambe counter"""
# need to reset the number of days since harambe was last mentioned
# 1. check if the server has ever crumbed before
# -> either reset date to current time or start a counter
if ctx.message.server is None:
return # probably a PM
server_id = (ctx.message.server.id,)
cls_.c.execute('select * from harambe where server=?',
server_id)
result = cls_.c.fetchone()
# result = [server, last, number, chain, max]
if result is not None:
# previous server
# message.timestamp is a native datetime.datetime object
# so in the database we are storing a datetime.datetime object
# (=> str(datetime.datetime), it's a string-encoded ISO-based date)
d_last = datetime.datetime.strptime(result[1], '%Y-%m-%d %H:%M:%S.%f')
d_new = ctx.message.timestamp
d = (str(d_new),)
d_diff = d_new - d_last
if d_diff.days >= 2:
# update last in db
cls_.c.execute('''update harambe
set last=?, number=number+1, chain=0
where server=?''', [d[0], server_id[0]])
cls_.conn.commit()
await cls_.bot.send_message(ctx.message.channel,
'days since harambe was last mentioned: %s --> 0'
% d_diff.days)
elif d_diff.days == 1:
if result[3] >= result[4]:
cls_.c.execute('update harambe set max=?', (result[3] + 1,))
cls_.c.execute('''update harambe
set last=?, number=number+1, chain=chain+1
where server=?''', [d[0], server_id[0]])
cls_.conn.commit()
await cls_.bot.send_message(ctx.message.channel,
'daily harambe chain: %s' % str(result[3] + 1))
else:
cls_.c.execute('''update harambe
set number=number+1
where server=?''', server_id)
if config.DEBUG:
await cls_.bot.send_message(ctx.message.channel,
'[moobot debug]: %s %s %s'
% (str(d_diff), result[2], result[3]))
else:
# new server to the harambe meme
# just store the current time
d_new = ctx.message.timestamp
d = (str(d_new),)
cls_.c.execute('insert into harambe values (?, ?, 1, 0, 0)',
[server_id[0], d[0]])
cls_.conn.commit()
async def f(cls_, ctx):
"""respect"""
# we do two things:
# 1. we increment their respect tallies in sqlite
# 2. we let everyone know how respectful they are
u = (ctx.message.author.id,)
cls_.c.execute('select * from respect where user=?', u)
u_ = cls_.c.fetchone()
if u_ is not None:
cls_.c.execute('update respect set f=f+1 where user=?', u)
cls_.conn.commit()
else:
# add user to db
cls_.c.execute('insert into respect values(?, 1)', u)
cls_.conn.commit()
await cls_.bot.send_message(ctx.message.channel,
'%s p-p-pays their respects... BAKA' % ctx.message.author.mention)
async def respect(cls_, ctx):
"""respect count"""
real = ctx.message.content.lower() in ['actualrespect', 'realrespect']
r = 0
if not real and ctx.message.author.id in config.fixed_karma:
# we have the leet effect
r = str(config.fixed_karma[ctx.message.author.id])
else:
# we're asked for how much respect someone has
u = (ctx.message.author.id,)
cls_.c.execute('select * from respect where user=?', u)
result = cls_.c.fetchone()
if result is not None:
r = str(result[1])
await cls_.bot.send_message(ctx.message.channel,
'*%s*: %s respect... NOT LIKE I LIKE YOU OR ANYTHING' % (ctx.message.author.mention, r))
async def top_respect(cls_, ctx):
"""moobot will output the global respect leaders"""
my_members = {}
for row in cls_.c.execute('select * from respect'):
# row -> ( 'user id', amount )
memer = ctx.message.server.get_member(row[0])
if memer is not None:
# keep
my_members[row[0]] = { 'score' : row[1],
'name': memer.display_name }
# listify members
members_stripped = list(my_members.values())
# limit results
members_stripped.sort(key=lambda member: member['score'], reverse=True)
members_stripped = members_stripped[:30]
message = 'the respect scores are as follows:\n```'
for member in members_stripped:
message += '{} - {} respect\n'.format(member['name'], member['score'])
message += '```'
# print(message)
await cls_.bot.send_message(ctx.message.channel,
message)
async def emojii_pasta(cls_, ctx):
"""translates text to emojii, see emojiityper.com"""
pass
async def with_rice(cls_, ctx):
"""the spicy with rice meme,
gone from plaguing reddit to plaguing discord"""
are_we_riced = 'rice' in ctx.message.content.lower()
# TODO: this
async def one_two_two_two_three_four_five(cls_, ctx):
"""don't ask"""
await cls_.bot.send_message(ctx.message.channel, ctx.message.content)