-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
242 lines (189 loc) · 7.3 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
# TimApple Bot beta Version
import discord
import requests
import json
import time
import random
import csv
import wolframalpha
from decouple import config
from keep_alive import keep_alive
from image_process import Certificate
from QuoteEng import qandaJokes, hindiJokes, salut
############
# token and keys from Environment Variables
############
TOKEN = config('TOKEN') #discord token from env
app_id = config('APP_ID') #wolfram alpha app id from env
rapidapi_key = config('RAPIDAPI-KEY')
wolfram = wolframalpha.Client(app_id)
# init discord client
client = discord.Client()
# list of curse words created using csv
# TODO: move to new python file and import
load_words = []
curse_file = "censor/bad-words-en.csv"
with open(curse_file, 'r') as word:
for i in csv.reader(word):
load_words.append(i)
curse_en = []
for i in load_words:
index = load_words.index(i)
curse_en.append(load_words[index][0])
load_words.clear()
curse_file = "censor/bad-words-hindi.csv"
with open(curse_file, 'r') as word:
for i in csv.reader(word):
load_words.append(i)
curse_hi = []
for i in load_words:
index = load_words.index(i)
curse_hi.append(load_words[index][0])
# messages if curse words are used in the server
anti_curse_en = [
"Courage is fire, and bullying is smoke.",
"Not all forms of abuse leave bruises.",
"I would rather be a little nobody than to be an evil somebody.",
"If I were two-faced, would I be wearing this one?",
"The average dog is a nicer person than you!",
""
]
anti_curse_hi = [
"मेरा मुंह मत खुलवाओ!",
"में आजकल रंग बदलने में लोगों का मुकाबला नहीं कर पा रहा हूं!!",
"तारीफों से भी जिंदा रह सकते हैं..",
"सूखे हुए पत्तों की तरह मत बनाओ अपनी जिंदगी!",
"शरीफों की शराफत और हमारा,कमीनापन किसी को अच्छा, नहीं लगता!!",
"lol XD mai kaise maan lu?",
"गाली मत दो भाई!",
"कृपया कोई बदमाशी न करें",
"मैं अपमानजनक चैट बर्दाश्त नहीं करूंगा!",
"भाई आराम से",
"भाई तू चुप कर ले"
]
################
# apis
################
def get_quote():
response = requests.get('https://zenquotes.io/api/random')
json_data = json.loads(response.text)
quote = json_data[0]['q'] + " -" + json_data[0]['a']
# quote = json_data[0]['h']
return(quote)
def evil_insult():
response = requests.get(
'https://evilinsult.com/generate_insult.php?lang=en&type=json')
json_data = json.loads(response.text)
insult = json_data['insult']
return(insult)
def ask_que(question):
res = wolfram.query(question)
answer = next(res.results).text
return answer
def dad_jokes():
url = "https://dad-jokes.p.rapidapi.com/random/joke"
headers = {
'x-rapidapi-key': rapidapi_key,
'x-rapidapi-host': "dad-jokes.p.rapidapi.com"
}
response = requests.request("GET", url, headers=headers)
json_data = json.loads(response.text)
joke = {}
joke['que'] = json_data['body'][0]['setup']
joke['ans'] = json_data['body'][0]['punchline']
return joke
################
# main bot code
################
@client.event
async def on_ready():
branding = """
╔╦╗┬┌┬┐ ╔═╗┌─┐┌─┐┬ ┌─┐
║ ││││ ╠═╣├─┘├─┘│ ├┤
╩ ┴┴ ┴ ╩ ╩┴ ┴ ┴─┘└─┘
"""
print(branding)
print("Logged in as {0.user}".format(client))
print("Bot created by Tushar G. (github.com/tushgaurav)")
await client.change_presence(activity=discord.Game('$help | linktr.ee/TimApple'))
@client.event
async def on_message(message):
if message.author == client.user:
return
msg = message.content
author = (message.author)
previous_status = client.guilds[0].get_member(client.user.id).activity
#################
# bot functions
#################
if msg.startswith('$hello'):
text = salut()
await message.channel.send(f"{text[0]}, from {text[1]}")
# TODO: work on this function
if msg.startswith('$introduce'):
await message.channel.send('I am your dad ' + author.mention)
if msg.startswith('$gyan'):
quote = get_quote()
await message.channel.send(quote)
if msg.startswith('$roast'):
insult = evil_insult()
await message.channel.send(insult)
# TODO: add meme functionality
if msg.startswith('$meme'):
await message.channel.send("You are a living meme " + author.mention)
if msg.startswith('$ask'):
question = msg[5:]
res = ask_que(question)
await message.channel.send(res)
if msg.startswith('$listen'):
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name='to sad noises!'))
await message.channel.send("I am now listening to sad noises")
time.sleep(10)
await client.change_presence(activity=previous_status)
if msg.startswith('$dadjoke'):
dadjoke = dad_jokes()
await message.channel.send(dadjoke['que'])
time.sleep(5)
await message.channel.send(dadjoke['ans'])
if msg.startswith('$help'):
await message.channel.send(file=discord.File('./images/TimApple.jpg'))
await message.channel.send(
'''
**Tim Apple v0.2 Beta** ***Waifu Inc.***
Bot Commands:
$hello - Say Hi to the bot
$introduce - Bot will introduce
$gyan - Bot will send a Motivational quote
$roast - Bot will roast you
$hindi - Get a hinid joke
$joke - Get a joke in the form of a question and answer
$meme - Bot will send a meme (Under Development)
$dadjoke - Bot will send a dad joke
$ask - You can ask any question after this command like `$ask What is Rick Rolling`
$listen - It will do something
$certificate - Will award you with a certificate of achievement
''')
# sends a the bot website
if msg.startswith('$invite'):
await message.channel.send('https://linktr.ee/TimApple')
if msg.startswith('$certificate'):
text = str(message.author)
Certificate(text)
await message.channel.send(file=discord.File('./images/output.png'))
# send hindi jokes
if msg.startswith('$hindi'):
await message.channel.send(hindiJokes())
# send english jokes in the form of question and answers
if msg.startswith('$joke'):
joke = qandaJokes()
await message.channel.send(joke[0])
time.sleep(3)
await message.channel.send(joke[1])
# anti curse features, needs work to be done, false positives
if any(word in msg for word in curse_en):
await message.channel.send(random.choice(anti_curse_en))
elif any(word in msg for word in curse_hi):
await message.channel.send(random.choice(anti_curse_hi))
# function to keep the bot online on replit.com (simple hacks)
keep_alive()
client.run(TOKEN)