-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTooManyCooks.py
More file actions
332 lines (290 loc) · 11.9 KB
/
TooManyCooks.py
File metadata and controls
332 lines (290 loc) · 11.9 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
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
import datetime
import asyncio
from discord.ext import commands
import discord
import Moodle as mood
import random
import requests
from youtube_dl import YoutubeDL
import os
import giphy_client
from giphy_client.rest import ApiException
import csv
from discord import FFmpegPCMAudio
import re
TOKEN = os.environ.get("TOKEN")
courses = {"qazi": "CMPG 780 Linux Kernel Programming", "igor": "CMPT 465 Neural Networks and Learning Systems", "miaomiao": "CMPG 667 Computer Networking", "aggie": "CMPG 638 Design&Analy of Algorithms"}
version = 'v1.5'
bot = commands.Bot(command_prefix=commands.when_mentioned_or('-'))
giphy_token = os.environ.get("G-TOKEN")
api_instance = giphy_client.DefaultApi()
players ={}
class Main(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.total = 1.00
@commands.command(pass_context=True)
async def moodle(self, ctx, message: str):
if message in courses.keys():
instance = mood.Moodle()
courseData = instance.findCourse(message)
titles, hrefs = instance.parsingCourseData(courseData)
embed = discord.Embed()
embed.set_author(name='Manhattan College Moodle LMS') # title of course
embed.title = courses[message] # name of link to course page
embed.url = 'https://lms.manhattan.edu/my/' # actual link to course
embed.description = version # description
embed.set_thumbnail(url=ctx.author.avatar_url) # image top right small
embed.colour = ctx.author.colour # left line color
count = 0
for title in titles:
embed.add_field(name=title, value=hrefs[count], inline=False)
count += 1
embed.set_footer(text='In Development')
await ctx.send(embed=embed)
else:
await ctx.send("Command not Found!")
@commands.command(pass_context=True)
async def hw(self, ctx, message: str):
if message in courses.keys():
instance = mood.Moodle()
courseData = instance.findCourse(message)
assignments = instance.assignments(courseData)
embed = discord.Embed()
embed.set_author(name='Manhattan College Moodle LMS') # title of course
embed.title = courses[message] # name of link to course page
embed.url = 'https://lms.manhattan.edu/my/' # actual link to course
embed.description = version # description
embed.set_thumbnail(url=ctx.author.avatar_url) # image top right small
embed.colour = ctx.author.colour # left line color
for hw in assignments:
ddobj = datetime.datetime.strptime(assignments[hw][0], '%A, %B %d, %Y, %I:%M %p')
if (datetime.datetime.now() < ddobj):
embed.add_field(name='{} --- **ACTIVE**'.format(hw),
value='{}\nDue Date: {}'.format(assignments[hw][1], assignments[hw][0]), inline=False)
else:
embed.add_field(name='{} --- **IN-ACTIVE**'.format(hw),
value='{}\nDue Date: {}'.format(assignments[hw][1], assignments[hw][0]), inline=False)
embed.set_footer(text='In Development')
await ctx.send(embed=embed)
@commands.command(pass_context=True)
async def sanjay(self, ctx):
author = ctx.message.author.id
a = '<@{0}>'.format(author)
msg = ', did you know Sanjay is god?'
await ctx.send(a + msg)
@commands.command(pass_context=True)
async def eric(self, ctx):
a = ['LIGMA', 'SUGMA', 'SUGONDESE', 'SUKAPONMA', 'SLUrPONDESE', 'FUGMA', 'BOFA', 'EETMA']
lol = random.randint(0, 7)
ericid = '<@104348613735358464>'
msg = ' has been infected with '
await ctx.send(ericid + msg + a[lol])
@commands.command(pass_context=True)
async def natalie(self, ctx):
natid = '<@534788195964157952>'
self.total += 0.01
msg = ' has been given 1 cent. Her total balance is '
await ctx.send(natid + msg + "{:.2f}".format(self.total))
@commands.command(pass_context=True)
async def mike(self, ctx):
mikeid = 298282227047989262
print(ctx.author.id)
if ctx.author.id == mikeid:
await ctx.send("Mike is here!")
else:
await ctx.send("You are An Impostor")
@commands.command(pass_context=True)
async def jeremy(self, ctx):
await ctx.send("Jeremy use to eat chapstick in Kindergarten")
@commands.command(pass_context=True)
async def emelia(self, ctx):
await ctx.send("Doc Martens is not a personality trait")
@commands.command(pass_context=True)
async def spam(self, ctx):
striy = ctx.message.content
strigy = striy[6:]
lol = random.randint(4, 8)
for x in range(0,lol):
await ctx.send(strigy)
@commands.command(pass_context=True)
async def gif(self, ctx):
stry = ctx.message.content
strgy = stry[5:]
gif = await search_gifs(strgy)
with open('D:\\Downloads\\buss.gif', 'wb') as f:
f.write(requests.get('https://media.giphy.com/media/' + gif + '/giphy.gif').content)
await ctx.send(file=discord.File('D:\\Downloads\\buss.gif'))
@commands.command(pass_context=True)
async def vote(self, ctx, message: str):
stry = message.capitalize()
votedict = {}
with open('voting.csv') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for row in csv_reader:
votedict[row[0]] = row[1]
with open('voting.csv', mode='w', newline='') as vwf:
writer = csv.writer(vwf, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
if stry in votedict.keys():
temp = votedict[stry]
count = int(temp)
count += 1
votedict[stry] = str(count)
else:
votedict[stry] = '1'
for line in votedict.keys():
writer.writerow([line, votedict[line]])
await ctx.send("Vote Submitted")
@commands.command(pass_context=True)
async def result(self, ctx):
myid = 235185011941310468
print(ctx.author.id)
if ctx.author.id == myid:
votedict = {}
with open('voting.csv') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for row in csv_reader:
votedict[row[0]] = row[1]
await ctx.send(str(votedict))
else:
await ctx.send("Results will be revealed on Election Day!")
@commands.command(pass_context=True)
async def loading(self, ctx):
y = 1
dot = ' . '
msg = await ctx.send('Loading')
while y <= 2:
con = 'Loading'
x = 1
while x <= 10:
await asyncio.sleep(0.5)
await msg.edit(content=con)
con += dot
x += 1
y += 1
@commands.command(pass_context=True)
async def time(self, ctx):
timestr = ctx.message.content
time = int(timestr[6:])
count = time
msg = await ctx.send(str(time))
while count > 0:
count -= 1
await asyncio.sleep(1)
await msg.edit(content=str(count))
@commands.command(pass_context=True)
async def embed(self, ctx):
embed = discord.Embed()
embed.set_author(name='School') #title of course
embed.title = 'KSFSKDJSKFH' #name of link to course page
embed.url = 'https://www.google.com/' #actual link to course
embed.description = 'description' #description
embed.set_thumbnail(url='https://interactive-examples.mdn.mozilla.net/media/cc0-images/grapefruit-slice-332-332.jpg') #image top right small
embed.colour = 0x046a38 #left line color
embed.add_field(name='Syllabus', value='[test](https://www.google.com/)')
embed.set_footer(text='Challenge Released')
await ctx.send(embed=embed)
@commands.command(pass_context=True)
async def yt(self, ctx):
emeliaid = 442044853728051200
print(ctx.author.id)
if ctx.author.id != emeliaid:
striy = ctx.message.content
strgy = striy[4:]
url = self.getYTurl(strgy)
await ctx.send(url)
else:
await ctx.send("Emelia it is a NO for you!")
def getYTurl(self, ctx):
y = 0
output = re.sub(' ', '+', ctx)
session = requests.Session()
api = os.environ.get("Y-API")
maxResults = "20"
query = output
print('Query:', query)
url = "https://www.googleapis.com/youtube/v3/search?part=snippet" \
"&q=" + query + \
"&key=" + api + \
'&maxResults=' + maxResults
reqJson = session.get(url).json()
# numResults = int(reqJson['pageInfo']['resultsPerPage'])
while reqJson['items'][y]['id']['kind'] != "youtube#video" and y < int(maxResults):
y += 1
if reqJson['items'][y]['id']['kind'] == "youtube#video":
video = "https://www.youtube.com/watch?v=" + reqJson['items'][y]['id']['videoId']
return str(video)
else:
return None
@commands.command(pass_context=True)
async def play(self, ctx):
striy = ctx.message.content
strgy = striy[6:]
url = self.getYTurl(strgy)
YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True', 'geo_bypass': 'True'}
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
x = 10
author = ctx.message.author
if author.voice is None:
await ctx.send("Join a Voice Channel")
while x > 0 and author.voice is None:
await asyncio.sleep(1)
x -= 1
if author.voice is None:
await ctx.send(
"You have somehow failed a simple task of joining a voice channel within 10 seconds. Very Sad.")
return
voice = await author.voice.channel.connect()
print(voice)
if not voice.is_playing():
with YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(url, download=False)
URL = info['formats'][0]['url']
voice.play(FFmpegPCMAudio(URL, **FFMPEG_OPTIONS))
voice.is_playing()
else:
await ctx.send("Already playing song")
return
msg = "Should Be Playing"
await ctx.send(msg)
mem = author.voice.channel.members
mount = 0
print(mem)
while voice.is_playing():
await asyncio.sleep(3)
if not (voice.is_playing()):
await ctx.voice_client.disconnect()
print("Bot left the voice channel")
@commands.command(pass_context=True)
async def leave(self, ctx):
try:
await ctx.voice_client.disconnect()
except:
print("Not Important")
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
async def search_gifs(query):
try:
response = api_instance.gifs_search_get(giphy_token, query, limit=10, rating='r')
lst = list(response.data)
gif = random.choices(lst)
return gif[0].id
except ApiException as e:
return "Exception when calling DefaultApi->gifs_search_get: %s\n" % e
async def on_message(message):
emeliaId = 442044853728051200
msg = message.content.lower()
msg = re.sub(r'[^a-z]+', '', msg)
if message.author.id == emeliaId and 'interesting' in msg:
a = '<@{0}>'.format(message.author.id)
msg = ', You are not permitted to use the word **interesting**. Please refrain from using it!'
channel = message.channel
await channel.send(a + msg)
else:
return
bot.add_cog(Main(bot))
bot.run(TOKEN)