-
Notifications
You must be signed in to change notification settings - Fork 2
/
computer_cell_bot.py
190 lines (141 loc) · 4.17 KB
/
computer_cell_bot.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
import discord
import random
from io import BytesIO, StringIO
import base64
from numpy import *
import numpy as np
import matplotlib.pyplot as plt
from discord.ext import commands
# last one sitting universe
#TODO: Add channel ID HERE
channels = [0000000]
VC = ""
bot = commands.Bot(command_prefix=">")
from corpora import Corpora
Corpora(bot)
"""
------------------------------
Members
------------------------------
"""
@bot.command("docs")
async def hello(ctx):
with open("help.txt") as afile:
docs = afile.read()
await ctx.send(docs)
"""
------------------------------
JOKES
------------------------------
"""
@bot.group()
async def joke(ctx):
if ctx.invoked_subcommand is None:
await ctx.send("Invalid command passed...")
@joke.command()
async def comp(ctx):
with open("computer_jokes.txt") as afile:
roasts = afile.readlines()
roast = random.choice(roasts)
await ctx.send(roast)
@joke.command()
async def git(ctx):
with open("git_jokes.txt") as afile:
roasts = afile.readlines()
roast = random.choice(roasts)
await ctx.send(roast)
"""
------------------------------
meme name
------------------------------
"""
@bot.group()
async def make(ctx):
pass
@make.command()
async def doge(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)
await ctx.send(link)
@make.command()
async def buzz(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)
await ctx.send(link)
"""
------------------------------
mock name <>
------------------------------
"""
import urllib
@bot.group()
async def mock(ctx):
if ctx.invoked_subcommand is None:
await ctx.send("Invalid command passed...")
@mock.command()
async def name(ctx, name: str):
with open("name_mock.txt") as afile:
name_mocks = afile.readlines()
for line in name_mocks:
if line.startswith(name.upper()):
await ctx.send("{}".format(line))
return
"""
------------------------------
DANGER: Math commands
------------------------------
"""
import sympy
@bot.group()
async def math(ctx):
if ctx.invoked_subcommand is None:
await ctx.send("Invalid command passed...")
@math.command()
async def diff(ctx, equation: str, variable: str):
try:
ans = sympy.diff(equation, variable)
except:
ans = "Erro Occured."
await ctx.send(
"=tex \\begin{{align*}} {0} \\end{{align*}}".format(sympy.latex(ans))
)
return
@math.command()
async def integrate(ctx, equation: str, variable: str, upperlimit, lowerlimit):
try:
ans = sympy.integrate(equation, (variable, upperlimit, lowerlimit))
except:
ans = "Erro Occured."
await ctx.send(
"=tex \\begin{{align*}} {0} \\end{{align*}}".format(sympy.latex(ans))
)
return
@math.command()
async def plot(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) for x in X]
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()
for i in channels:
channel = bot.get_channel(i)
try:
if channel.name == ctx.message.channel.name:
file = discord.File(figure, filename="plot.png")
await channel.send("Powered by matplotlib", file=file)
except AttributeError:
print("AttributeError")
API_KEY = "ADD API KEY HERE"
bot.run(API_KEY)