-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
311 lines (253 loc) · 10.6 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
import discord, random
import asyncio
import aiohttp, io
import wolframalpha
import pytz
import play_lichess
from play_lichess.constants import Variant
from datetime import datetime
from discord import Activity, ActivityType, Status
from discord.ext import tasks
from discord.ext import commands
from googletrans import Translator # pip install googletrans==3.1.0a0
# USE THE ALPHA VERSION
from alive import alive
from reddit import get_image
from dotenv import load_dotenv # .env
import os
load_dotenv()
#--------------------------------------VARIABLES------------------------------
TOKEN = os.getenv("DISCORD_TOKEN")
help_command = commands.DefaultHelpCommand(no_category="Here, get some help from jeff")
intents = discord.Intents.all()
client = commands.Bot(command_prefix=['jeff '], case_insensitive=True, intents=intents, help_command=help_command)
wolfram_client = wolframalpha.Client(os.getenv("WOLFRAM_APP_ID"))
montreal_tz = pytz.timezone('America/Montreal')
#---------------------------------INITIALIZE-------------------------------------
@client.event
async def on_ready():
print('{0.user} is alive'.format(client))
await client.change_presence(status=Status.idle, activity=Activity(type=ActivityType.watching, name="you"))
#------------------------------COMMANDS----------------------------------
#Lichess Link
@client.command(brief="Generate Lichess Link", description="""
clock_limit (default) = 600
clock_increment (default) = 3
Variants:
STANDARD (default)
CRAZYHOUSE
CHESS960
KING_OF_THE_HILL
THREE_CHECK
ANTICHESS
ATOMIC
HORDE
RACING_KINGS
""", aliases=['lichess'])
async def chess(ctx, clim=600, cinc=3, gametype="STANDARD"):
if gametype.upper() == "STANDARD":
variant = Variant.STANDARD
elif gametype.upper() == "CRAZYHOUSE":
variant = Variant.CRAZYHOUSE
elif gametype.upper() == "CHESS960":
variant = Variant.CHESS960
elif gametype.upper() == "KING_OF_THE_HILL":
variant = Variant.KING_OF_THE_HILL
elif gametype.upper() == "THREE_CHECK":
variant = Variant.THREE_CHECK
elif gametype.upper() == "ANTICHESS":
variant = Variant.ANTICHESS
elif gametype.upper() == "ATOMIC":
variant = Variant.ATOMIC
elif gametype.upper() == "HORDE":
variant = Variant.HORDE
elif gametype.upper() == "RACING_KINGS":
variant = Variant.RACING_KINGS
else:
variant = Variant.STANDARD # Default to STANDARD if no match is found
await ctx.send(f'Selected Variant: {variant}')
try:
match = play_lichess.create(
minutes=clim,
increment=cinc,
variant=variant
)
await ctx.send(f"Chess Game Link: {match.link}")
except Exception as e:
await ctx.send(f'Error: {str(e)}')
@client.command(brief="Math Solver.", aliases=['m'])
async def math(ctx, *, query):
try:
res = await wolfram_client.query(query)
result = None
for pod in res.pods:
if pod.primary:
result = pod.subpods[0].plaintext
break
if result:
embed = discord.Embed(title=f"Query: {query}", color=discord.Color.random())
embed.add_field(name="Result", value=result, inline=False)
await ctx.send(embed=embed)
else:
await ctx.send("No results found.")
except Exception as e:
await ctx.send(f"An error occurred: {str(e)}")
# Translate
@client.command(brief="Google Translate.", description="""
'ch': 'chinese (simplified)',
'cht': 'chinese (traditional)',
'en': 'english',
'fr': 'french',
'ge': 'german',
'gr': 'greek',
'he': 'hebrew',
'hi': 'hindi',
'hu': 'hungarian',
'it': 'italian',
'ja': 'japanese',
'ko': 'korean',
'la': 'latin',
'pe': 'persian',
'po': 'polish',
'pu': 'punjabi',
'ru': 'russian',
'sp': 'spanish',
'tu': 'turkish'""", aliases=['trans', 'tr'])
async def translate(ctx, lang='en', *, text):
try:
translator = Translator()
if lang in ['ch', 'cn', 'chinese']:
lang = 'zh-cn'
elif lang in ['cht', 'cnt', 'chineset']:
lang = 'zh-tw'
elif lang in ['gr', 'greek']:
lang = 'el'
elif lang in ['ge', 'german']:
lang = 'de'
elif lang in ['pu', 'punjabi']:
lang = 'pa'
elif lang in ['tu', 'turkish']:
lang = 'tr'
elif lang in ['pe', 'persian']:
lang = 'fa'
elif lang in ['sp', 'spanish']:
lang = 'es'
elif lang in ['po', 'polish']:
lang = 'pl'
translation = translator.translate(text, dest=lang)
await ctx.send(translation.text)
except ValueError as e:
await ctx.send(f'Error: {str(e)}')
@client.command(brief="Status checking", aliases=['stat']) # Status
async def status(ctx):
await ctx.send('alive')
@client.command(brief="Images subreddit", aliases=['red']) # Reddit
async def reddit(ctx):
image_url, post_title, embed_color = await get_image()
embed = discord.Embed(title=post_title, color=discord.Color(embed_color))
embed.set_image(url=image_url)
await ctx.send(embed=embed)
@client.command(brief="Who just deleted a message?") # Snipe
async def snipe(ctx):
global snipe_message_content, snipe_message_author, snipe_message_channel, snipe_message_attachments
if snipe_message_content is None:
await ctx.channel.send("There is nothing to snipe")
return
embed = discord.Embed(description=snipe_message_content, color=discord.Color.random())
embed.set_author(name=f"{snipe_message_author.name} sent:")
embed.set_footer(text=f"#{snipe_message_channel.name} | You cannot escape jeff.")
if snipe_message_attachments:
embed.set_image(url=snipe_message_attachments[0])
await ctx.channel.send(embed=embed)
@client.command(brief="jeff decides for you.") # Choose
async def choose(ctx, *, options):
if len(options) < 2:
await ctx.send("Not enough choices")
else:
options_list = options.split(",")
chosen_option = random.choice(options_list)
await ctx.send(f"jeff chooses {chosen_option.strip()}")
@client.command(brief="latency") # Latency
async def latency(ctx):
latency = client.latency
await ctx.send(f"Latency: {latency}")
@client.command(brief="Repeating argument x, for y number of times") # Repeating arg.
async def repeat(ctx, argument: str, times: int):
for i in range(times):
await ctx.send(argument)
@client.command(brief="Changing the user's server name") # Change Nick scrapped from channel 971882706331926558
async def change(ctx):
try:
channel = client.get_channel(971882706331926558)
if channel is None:
await ctx.send("Failed to get the channel.")
return
nicknames = []
async for message in channel.history(limit=None):
if message.author != client.user:
nicknames.append(message.content)
member = ctx.guild.get_member(688182572467093504)
if member is None:
await ctx.send("Failed to get the member.")
return
current_nickname = member.nick or member.name
new_nickname = current_nickname
while new_nickname == current_nickname:
new_nickname = random.choice(nicknames)
await member.edit(nick=new_nickname)
await ctx.send(f'Changed to {new_nickname}.')
except Exception as e:
await ctx.send(f"An error occurred: {str(e)}")
@client.command(brief="Changing Profile Pic", aliases=['pp']) #Change Profile Pic
async def profilepic(ctx):
try:
url, title, color = await get_image()
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
if resp.status != 200:
await ctx.send(f"Failed to download image from {url}")
return
image_bytes = await resp.read()
image = io.BytesIO(image_bytes)
await client.user.edit(avatar=image.getvalue())
await ctx.send(f"Changed profile picture to [ {title} ] ({url}).")
except Exception as e:
await ctx.send(f"An error occurred: {str(e)}")
# -------------------------------------EVENTS------------------------
snipe_message_content = None
snipe_message_author = None
snipe_message_channel = None
snipe_message_attachments = []
@client.event # Upon message deletion
async def on_message_delete(message):
global snipe_message_content, snipe_message_author, snipe_message_channel, snipe_message_attachments
snipe_message_content = message.content
snipe_message_author = message.author
snipe_message_channel = message.channel
snipe_message_attachments = [attachment.url for attachment in message.attachments if attachment.url.endswith(('jpg', 'jpeg', 'png', 'gif'))]
@client.event # Upon Member Join
async def on_member_join(member):
general_channel = client.get_channel(649297818699169805)
welcome_message = f"{member.mention} has just joined the server"
await general_channel.send(welcome_message)
#VC CHECK
voice_channel_id = 697798692958109746 #Arg
target_channel_id = 712674217480683563 #Announcement
target_role_id = 1106591530296279190 #VCNotif
users_in_channel = set()
@client.event #VC notify
async def on_voice_state_update(member, before, after):
voice_channel = client.get_channel(voice_channel_id)
if before.channel != voice_channel and after.channel == voice_channel:
if len(voice_channel.members) == 1:
target_channel = client.get_channel(target_channel_id)
target_role = discord.utils.get(member.guild.roles, id=target_role_id)
if target_channel is not None and target_role is not None:
await target_channel.send(f'{target_role.mention} someone just joined vc at {datetime.now(montreal_tz).strftime("%I:%M %p")}')
if before.channel == voice_channel and after.channel != voice_channel:
if len(voice_channel.members) == 0:
target_channel = client.get_channel(target_channel_id)
if target_channel is not None:
await target_channel.send(f'Everybody left vc at {datetime.now(montreal_tz).strftime("%I:%M %p")}')
alive()
client.run(TOKEN)