Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcomputer_cell_bot.py
More file actions
Latest commit
190 lines (141 loc) · 4.17 KB
/
Copy pathcomputer_cell_bot.py
File metadata and controls
190 lines (141 loc) · 4.17 KB
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
importdiscord
importrandom
fromioimportBytesIO, StringIO
importbase64
fromnumpyimport*
importnumpyasnp
importmatplotlib.pyplotasplt
fromdiscord.extimportcommands
# last one sitting universe
#TODO: Add channel ID HERE
channels= [0000000]
VC=""
bot=commands.Bot(command_prefix=">")
fromcorporaimportCorpora
Corpora(bot)
"""
------------------------------
Members
------------------------------
"""
@bot.command("docs")
asyncdefhello(ctx):
withopen("help.txt") asafile:
docs=afile.read()
awaitctx.send(docs)
"""
------------------------------
JOKES
------------------------------
"""
@bot.group()
asyncdefjoke(ctx):
ifctx.invoked_subcommandisNone:
awaitctx.send("Invalid command passed...")
@joke.command()
asyncdefcomp(ctx):
withopen("computer_jokes.txt") asafile:
roasts=afile.readlines()
roast=random.choice(roasts)
awaitctx.send(roast)
@joke.command()
asyncdefgit(ctx):
withopen("git_jokes.txt") asafile:
roasts=afile.readlines()
roast=random.choice(roasts)
awaitctx.send(roast)
"""
------------------------------
meme name
------------------------------
"""
@bot.group()
asyncdefmake(ctx):
pass
@make.command()
asyncdefdoge(ctx, text_1, text_2):
text_1=urllib.parse.quote(text_1.replace(" ", "_"))
text_2=urllib.parse.quote(text_2.replace(" ", "_"))
link="https://memegen.link/doge/{}/{}.jpg".format(text_1, text_2)
awaitctx.send(link)
@make.command()
asyncdefbuzz(ctx, text_1, text_2):
text_1=urllib.parse.quote(text_1.replace(" ", "_"))
text_2=urllib.parse.quote(text_2.replace(" ", "_"))
link="https://memegen.link/buzz/{}/{}.jpg".format(text_1, text_2)
awaitctx.send(link)
"""
------------------------------
mock name <>
------------------------------
"""
importurllib
@bot.group()
asyncdefmock(ctx):
ifctx.invoked_subcommandisNone:
awaitctx.send("Invalid command passed...")
@mock.command()
asyncdefname(ctx, name: str):
withopen("name_mock.txt") asafile:
name_mocks=afile.readlines()
forlineinname_mocks:
ifline.startswith(name.upper()):
awaitctx.send("{}".format(line))
return
"""
------------------------------
DANGER: Math commands
------------------------------
"""
importsympy
@bot.group()
asyncdefmath(ctx):
ifctx.invoked_subcommandisNone:
awaitctx.send("Invalid command passed...")
@math.command()
asyncdefdiff(ctx, equation: str, variable: str):
try:
ans=sympy.diff(equation, variable)
except:
ans="Erro Occured."
awaitctx.send(
"=tex \\begin{{align*}} {0} \\end{{align*}}".format(sympy.latex(ans))
)
return
@math.command()
asyncdefintegrate(ctx, equation: str, variable: str, upperlimit, lowerlimit):
try:
ans=sympy.integrate(equation, (variable, upperlimit, lowerlimit))
except:
ans="Erro Occured."
awaitctx.send(
"=tex \\begin{{align*}} {0} \\end{{align*}}".format(sympy.latex(ans))
)
return
@math.command()
asyncdefplot(ctx, equation, x_min, x_max, delta_x):
plt.clf()
figure=BytesIO() # File like object to save png
x_min=float(x_min)
x_max=float(x_max)
delta_x=float(delta_x)
print("Equation:", equation)
X=np.arange(x_min, x_max, delta_x)
Y= [eval(equation) forxinX]
plt.plot(X, Y)
plt.ylabel(equation)
plt.xlabel("x")
plt.savefig(figure, format="png")
figure.seek(0)
# Encode data with base64 so it can be served
# figure = base64.standard_b64encode(figure.read()).decode()
foriinchannels:
channel=bot.get_channel(i)
try:
ifchannel.name==ctx.message.channel.name:
file=discord.File(figure, filename="plot.png")
awaitchannel.send("Powered by matplotlib", file=file)
exceptAttributeError:
print("AttributeError")
API_KEY="ADD API KEY HERE"
bot.run(API_KEY)