-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchungus.py
More file actions
130 lines (115 loc) · 4.69 KB
/
Copy pathchungus.py
File metadata and controls
130 lines (115 loc) · 4.69 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
import discord
import os
import numpy as np
from discord.ext import commands, tasks
from itertools import cycle
from config_vars import flag, discord_token
import help_info
import requests
import shutil
from PIL import Image
################################ DATA STRUCTURES ###############################
bot = commands.Bot(command_prefix = 'Oh Lord Chungus please ')
bot.remove_command('help')
extensions = ['tellme']
#################################### EVENTS ####################################
@bot.event # Show banner and add members to respective guilds in db
async def on_ready():
print("\n|--------------------|")
print(f"| {bot.user.name} - Online |")
print(f"| discord.py {discord.__version__} |")
print("|--------------------|")
await bot.change_presence(status=discord.Status.online, activity=discord.Game(name="My code is somewhere"))
@bot.event # Displays error messages
async def on_command_error(ctx, error):
msg = ""
if isinstance(error, commands.CommandNotFound):
return
if isinstance(error, commands.MissingRequiredArgument):
msg += "Missing a required argument. Display the help menu to see what commands you can run\n"
if isinstance(error, commands.MissingPermissions):
msg += "You do not have the appropriate permissions to run this command.\n"
if isinstance(error, commands.BotMissingPermissions):
msg += "I don't have sufficient permissions!\n"
if msg == "":
if not isinstance(error, commands.CheckFailure):
msg += "Something went wrong.\n"
print("error not caught")
print(error)
await ctx.send(msg)
else:
await ctx.send(msg)
@bot.event
async def on_message(ctx):
if str(ctx.channel.type) == "private" or str(ctx.channel.name) == "bot-commands":
await bot.process_commands(ctx)
if ctx.author.bot:
return
commands = ["help", "tellme ajoke", "tellme", "tellme theflag"]
start = 'Oh Lord Chungus please '
if str(ctx.channel.type) == "private" and start in str(ctx.content) and str(ctx.content).split(start)[1] in commands:
print("here")
first_check, msg = check1(str(ctx.author.avatar_url))
print(f'\n{first_check}\n{msg}\n')
if first_check:
if check2(str(ctx.created_at)):
await ctx.channel.send(f'`{flag}`')
else:
await ctx.channel.send("not the right time my friend")
else:
if len(msg) > 0:
await ctx.channel.send(msg)
elif msg == "nope":
await ctx.channel.send("no flag for you :pensive:")
################################ OTHER FUNCTIONS ###############################
@bot.command()
async def help(ctx, page=None):
if page == None:
emb = discord.Embed(description=help_info.help_page, colour=10181046)
else:
emb = discord.Embed(description=help_info.no_info, colour=10181046)
emb.set_author(name='ChungusBot v2 Help')
await ctx.channel.send(embed=emb)
def check2(hmm):
something = int(hmm.split(':')[-1].split('.')[0])
if (something > 45 and something < 50) or (something > 14 and something < 19):
return True
return False
def check1(av):
r = requests.get(str(av), stream = True)
if r.status_code == 200:
r.raw.decode_content = True
filename = str(str(av).split("/")[-1].split('?')[0])
path = f'./downloaded_files/{filename}'
with open(path,'wb') as f:
shutil.copyfileobj(r.raw, f)
else:
return False, "Could not grab your pfp for some reason"
img1 = list(Image.open('chungus_changed.jpg').convert("1").getdata())
img2 = list(Image.open(path).convert("1").getdata())
os.system(f"rm {path}")
bigger = len(img1)
if bigger > len(img2):
bigger = len(img2)
try:
count = 0
for i in range(bigger):
if img1[i] == img2[i]:
count += 1
except:
return False, "Image size not the same"
message = "Percentage of pixels correct: " + str(count / len(img1))
if count / len(img1) > 0.92:
return True, message
elif count / len(img1) > 0.6:
return False, message
else:
return False, f"Images are not the same ({100 * count / len(img1)}%)"
##################################### MAIN #####################################
if __name__ == '__main__': # Loads cog extentions and starts up the bot
print("\n|-----------------------|\n| Loaded Cogs: |")
for extension in extensions:
bot.load_extension('cogs.' + extension)
print("| - {} {}|".format(extension.upper(), " "*(15-len(extension))))
print("|-----------------------|\n")
bot.run(discord_token)