-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
375 lines (331 loc) · 10.5 KB
/
main.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
import os
import string
from datetime import date, datetime
from random import choice, randint
import pymongo
import discord
import requests
from botfunctions import (
actiongifs,
economy,
fiftyfifty,
helpandinfo,
misc,
pyrandtoys,
reddit,
textreplies,
)
from botfunctions.utility import find_keys, suggestcmd
from server import runserver
# loading env variables
try:
from dotenv import load_dotenv
load_dotenv()
except Exception as err:
print(err)
try:
# sharding
client = discord.AutoShardedClient(intents=discord.Intents.default())
# setting bot status
@client.event
async def on_ready():
await client.change_presence(activity=discord.Activity(
type=discord.ActivityType.listening, name="@mentions"))
print("We have logged in as {0.user}".format(client))
# uploading stats to discordbotlist
@client.event
async def on_guild_join(guild):
try:
gc = int(len(client.guilds))
uc = pymongo.MongoClient(os.environ.get("mongodb_connection_string"))["maindb"]["userdata"].count_documents({}) * 100 - randint(250, 500)
authtoken = os.getenv("dbl_token")
requests.post(
"https://discordbotlist.com/api/v1/bots/doge-memer/stats",
data={
"guilds": gc,
"users": uc
},
headers={"Authorization": authtoken},
)
except:
pass
# on message event
@client.event
async def on_message(message):
# suggestions channel
if (message.channel.id == 939056724197912576
and message.author != client.user and message.author.bot == False):
embed = discord.Embed(
title=f"Suggestion #{randint(1,10000)}",
description=message.content,
color=0x3498DB,
)
footd = date.today().strftime("%B %d, %Y")
foott = datetime.now().strftime("%H:%M:%S")
embed.set_footer(
text=f"Suggested by {message.author.name} on {footd} {foott}! ",
icon_url=message.author.avatar_url,
)
await message.channel.send(embed=embed)
await message.delete()
return
if message.channel.id == 851877024405520395 and message.author != client.user:
msg = message.content.lower()
msglist = msg.split()
if "voterid" in msglist:
id = msglist[2]
economy.inituser(int(id))
economy.addcoins(int(id), 1000)
try:
user = await client.fetch_user(id)
embed = discord.Embed(
title="Thanks For Voting!",
description=
"You just got your `⏣ 1000 NiTs` for voting on discordbotlist.com! You can vote again in 12hrs",
color=0x3498DB,
)
embed.set_image(url=choice([
"https://i.imgur.com/5BnTRl9.gif",
"https://i.imgur.com/NDdy6rz.gif",
"https://i.imgur.com/gKiQFHO.gif",
"https://i.imgur.com/mdsGwKS.gif",
"https://i.imgur.com/4LKknK9.gif",
"https://i.imgur.com/0kM45Ub.gif",
]))
await user.send(embed=embed)
await message.reply(f"User <@{id}> ({id}) got 1K for voting",
mention_author=False)
except:
await message.reply(f"User <@{id}> ({id}) got 1K for voting",
mention_author=False)
return
# blocking usage in dms
if (message.channel.type is discord.ChannelType.private
and message.author != client.user):
await message.reply(
choice([
"Stop sliding into my DMs you pervert!",
"Doge Memer answers only in servers \n**Add Doge Memer To Your Server** https://discordbotlist.com/bots/doge-memer",
"Give me sometime",
]),
mention_author=False,
)
return
if client.user.mentioned_in(message):
if message.author == client.user:
return
print("------------------------------------")
# lowering message content and removing other characters
content = message.content.lower()
content = content.translate(str.maketrans("", "", string.punctuation))
content = content.split(" ")
content = list(set(content))
content = content[:35]
print("Message Received (content) = ", content)
# removing client id from message list
content.remove(str(client.user.id))
print("Message without bot mention (content) = ", content)
fromid = message.author.id
print("Message sent by (fromid) = ", fromid)
# mapping names with ids using a dict and appending message mentions to a list
id_name_dict = {}
all_message_mentions = []
for mention in message.mentions:
id_name_dict[mention.id] = mention.name
if mention.id not in all_message_mentions:
all_message_mentions.append(mention.id)
print("ID to name mappings (id_name_dict) = ", id_name_dict)
print("All Message mentions (all_message_mentions) = ",
all_message_mentions)
all_message_mentions.remove(client.user.id)
print(
"Mentions in message other than bot (all_message_mentions) = ",
all_message_mentions,
)
try:
toid = all_message_mentions[0]
roastid = all_message_mentions[0]
except IndexError:
toid = None
roastid = None
########### commands list ##########
command_types = {
"💬 Text Reply Keywords": ["hello", "hi", "name"],
"🧠 NSFW Keywords": ["porn", "rule34"],
"😂 Fun Command Keywords": [
"50",
"bored",
"cards",
"coin",
"dice",
"fifty",
"roast",
],
"😎 Reddit Content Keywords": [
"art",
"comic",
"creepy",
"cringe",
"funny",
"irl",
"meme",
"twitter",
"wholesome",
],
"❤️ Interaction Keywords": [
"kill",
"kiss",
"lick",
"moment",
"pain",
"punch",
"slap",
],
"💰 Economy Keywords": ["balance", "bal", "beg", "vote"],
"🤖 Bot Info Keywords": ["coffee", "info", "server", "support"],
}
command_methodnames = {
"hello": textreplies.result,
"hi": textreplies.result,
"name": textreplies.result,
"roast": textreplies.result,
"kiss": actiongifs.result,
"kill": actiongifs.result,
"lick": actiongifs.result,
"moment": actiongifs.result,
"pain": actiongifs.result,
"punch": actiongifs.result,
"slap": actiongifs.result,
"meme": reddit.result,
"nigga": reddit.result,
"twitter": reddit.result,
"cringe": reddit.result,
"creepy": reddit.result,
"comic": reddit.result,
"funny": reddit.result,
"art": reddit.result,
"wholesome": reddit.result,
"irl": reddit.result,
"rule34": reddit.result,
"porn": reddit.result,
"50": fiftyfifty.result,
"fifty": fiftyfifty.result,
"balance": economy.balance,
"bal": economy.balance,
"info": helpandinfo.infoembed,
"coin": pyrandtoys.result,
"dice": pyrandtoys.result,
"cards": pyrandtoys.result,
"beg": economy.beg,
"bored": misc.bored,
"server": helpandinfo.serverlink,
"vote": misc.vote,
"coffee": misc.coffee,
"support": misc.coffee,
"help": helpandinfo.menu,
}
message_author_name = message.author.name
message_author_disc = message.author.discriminator
to_user_name = id_name_dict.get(toid, None)
command_params = {
"hello": ("hello", None),
"hi": ("hello", None),
"name": ("name", None),
"roast": ("roast", roastid),
"kiss": ("kiss", message_author_name, to_user_name),
"kill": ("kill", message_author_name, to_user_name),
"lick": ("lick", message_author_name, to_user_name),
"moment": ("moment", message_author_name, to_user_name),
"pain": ("pain", message_author_name, to_user_name),
"punch": ("punch", message_author_name, to_user_name),
"slap": ("slap", message_author_name, to_user_name),
"meme": ("default", None),
"nigga": ("BlackPeopleTwitter", None),
"twitter": ("tweets", None),
"cringe": ("cringepics", None),
"creepy": ("creepy", None),
"comic": ("comics", None),
"funny": ("funny", None),
"art": ("Art", None),
"wholesome": ("wholesomememes", None),
"irl": ("meirl", None),
"rule34": ("rule34", None),
"porn": ("porn", None),
"50": ("fiftyfifty", None),
"fifty": ("fiftyfifty", None),
"balance": (fromid, message_author_name, message_author_disc),
"bal": (fromid, message_author_name, message_author_disc),
"info": (len(client.guilds), client.user.avatar.url),
"coin": ("coin", None),
"dice": ("dice", None),
"cards": ("card", None),
"beg": (fromid, message_author_name, message_author_disc),
"bored": (message_author_name, None),
"server": (message_author_name, message.author.avatar.url),
"vote": (None, None),
"coffee": (message_author_name, message.author.avatar.url),
"support": (message_author_name, message.author.avatar.url),
"help": (command_types, None),
}
print("\nLength of method dict: ", len(command_methodnames))
print("Length of parameters dict: ", len(command_params))
########## ########## ######### #######
number_of_keys, keys_present_as_string, keys_present_as_list = find_keys(
content, command_methodnames)
# suggesting a command using suggestcmd of utility.py if no key is present in the message
if number_of_keys == 0:
try:
await message.reply(
suggestcmd(user_string=content[-1], commands=command_methodnames))
except IndexError:
await message.reply("Hey Noob! Try asking for help")
# more than one key present in message
elif number_of_keys > 1:
await message.reply(
f"What do you want exactly? **{keys_present_as_string}** \ncan't give em all at once!"
)
# only one key is present in the message
else:
# returned Tuple format => (message reply string, message reply embed, reply to message bool, mention author bool, dm bool)
(
replystr,
replyembed,
reply_bool,
mention_author_bool,
dm_bool,
) = command_methodnames[keys_present_as_list[0]](
*command_params[keys_present_as_list[0]])
if dm_bool == False:
if replystr != None:
if reply_bool == True:
await message.reply(replystr, mention_author=mention_author_bool)
else:
await message.channel.send(replystr)
else:
if reply_bool == True:
await message.reply(embed=replyembed,
mention_author=mention_author_bool)
else:
await message.channel.send(embed=replyembed)
else:
if replystr != None:
await message.author.send(replystr)
else:
try:
await message.author.send(embed=replyembed)
await message.reply("Check your dms 😋", mention_author=True)
except:
await message.reply(
"Allow dm from everyone in server privacy settings 😔 and try the command again!",
mention_author=True,
)
runserver()
try:
client.run(os.getenv("discord_bot_token"))
except Exception as err:
if err.status_code == 429:
os.system("kill 1")
except Exception as err:
print(err)
from os import system
system("kill 1")