-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobotum.py
179 lines (167 loc) · 8.2 KB
/
robotum.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
#============================================= All imports
import datetime
import discord,requests
from PIL import Image, ImageDraw, ImageFont, ImageFilter
import os
import random
import pymongo
import discord.utils
from io import BytesIO
from dotenv import load_dotenv
from discord.ext import commands
from keep_alive import keep_alive
#============================================= Intents
intents = discord.Intents.all()
intents.members = True
intents.presences = True
intents.message_content = True
robotum = commands.Bot(command_prefix=".", intents=intents, help_command=None)
clients = discord.Client(intents=intents)
#============================================= Connecting to MongoDB
uri = os.getenv("MONGOTOKEN")
client = pymongo.MongoClient(uri)
mydb = client["discord"]
mycol = mydb["member_roles"]
#============================================= If bot online it will print bot is online on console
@robotum.event
async def on_ready():
print('We have logged in as {0.user}'.format(robotum))
try:
client.admin.command('ping')
print("Pinged your deployment. You successfully connected to MongoDB!")
except Exception as e:
print(e)
#============================================= Checking bot is working or not
@robotum.command()
async def hello(ctx):
await ctx.send(f"Hello {ctx.author.mention}")
#============================================= Member join welcome embed
@robotum.event
async def on_member_join(member):
community = discord.utils.get(member.guild.roles, name="Community Members")
await member.add_roles(community)
channel = robotum.get_channel(917788968618168356)
embed=discord.Embed(title="𝓦𝓮𝓵𝓬𝓸𝓶𝓮!",description=f"{member.mention} Just Joined The Server.")
backgrounds =os.listdir('Images')
random_bg = random.choice(backgrounds)
img = Image.open("Images/" + random_bg)
if member.avatar == None:
font = ImageFont.truetype("ttf/KaushanScript-Regular.ttf", 75)
font2 = ImageFont.truetype("ttf/KaushanScript-Regular.ttf", 80)
text="Welcome"
draw=ImageDraw.Draw(img)
draw.text((600,100), text, (255, 255, 255), font=font, align='center')
draw.text((300,300), f"{member}", (255, 255, 255), font=font2, align='center' )
img.save("Images/text.png")
file = discord.File("Images/text.png", filename="Welcome.png")
embed.set_image(url="attachment://Welcome.png")
embed.timestamp = datetime.datetime.now()
else:
response = requests.get(member.avatar.url)
img2 = Image.open(BytesIO(response.content))
img2 = img2.resize((350,350))
mask_im = Image.new("L", (img2.width,img2.height), 0)
draw2 = ImageDraw.Draw(mask_im)
center_x, center_y = (175, 175)
radius = 160
left = center_x - radius
top = center_y - radius
right = center_x + radius
bottom = center_y + radius
circle_box = [(left, top), (right, bottom)]
draw2.ellipse(circle_box, fill=255)
blur = mask_im.filter(ImageFilter.GaussianBlur(10))
img.paste(img2, (575, 0), blur)
font = ImageFont.truetype("ttf/KaushanScript-Regular.ttf", 75)
font2 = ImageFont.truetype("ttf/KaushanScript-Regular.ttf", 80)
text="Welcome"
draw=ImageDraw.Draw(img)
draw.text((600,310), text, (255, 255, 255), font=font, align='center')
draw.text((300,400), f"{member}", (255, 255, 255), font=font2, align='center' )
img.save("Images/text.png")
file = discord.File("Images/text.png", filename="Welcome.png")
embed.set_image(url="attachment://Welcome.png")
embed.timestamp = datetime.datetime.now()
print (member)
await channel.send(file=file, embed=embed)
await member.send("Welcome to the Official KGEC Robotics Society Discord Server! \n\nThis is Robotum, the official bot of the server. We are glad that you joined us! 🤗 \n Please Check rules and information in the Server")
#============================================= Member left embed
@robotum.event
async def on_member_remove(member:discord.member):
channel = robotum.get_channel(918388896042209290)
embed=discord.Embed(title="🥹",description=f"{member.mention} Just Left The Server.")
embed.timestamp = datetime.datetime.now()
await channel.send(embed=embed)
#============================================= Giving role to member
@robotum.command()
async def verify(ctx):
print(ctx.author)
dbrole = mycol.find_one({"10" : str(ctx.author.id)})
dbrole2 = mycol.find_one({"10" : str(ctx.author)})
if dbrole == None and dbrole2 == None:
await ctx.send("Please copy your discord id and paste it on link and scan your qrcode. After scan you can give .verify command to get role. Link=")
elif dbrole == None:
await ctx.send(f"Hello {ctx.author.mention} Your roles are updated. Please check it out")
await ctx.author.edit(nick=str(dbrole2.get("0")))
if dbrole2.get("1") == "yes":
app = discord.utils.get(ctx.guild.roles, name="App Development")
await ctx.author.add_roles(app)
if dbrole2.get("2") == "yes":
iot = discord.utils.get(ctx.guild.roles, name="Internet Of Things(IoT)")
await ctx.author.add_roles(iot)
if dbrole2.get("3") == "yes":
ml = discord.utils.get(ctx.guild.roles, name="Machine Learning")
await ctx.author.add_roles(ml)
if dbrole2.get("4") == "yes":
cloud = discord.utils.get(ctx.guild.roles, name="Cloud Computing")
await ctx.author.add_roles(cloud)
if dbrole2.get("5") == "yes":
mechatronics = discord.utils.get(ctx.guild.roles, name="Mechatronics")
await ctx.author.add_roles(mechatronics)
if dbrole2.get("6") == "yes":
web = discord.utils.get(ctx.guild.roles, name="Web Development")
await ctx.author.add_roles(web)
if dbrole2.get("7") == "yes":
design = discord.utils.get(ctx.guild.roles, name="Design Team")
await ctx.author.add_roles(design)
if dbrole2.get("8") == "yes":
video = discord.utils.get(ctx.guild.roles, name="Video Editor")
await ctx.author.add_roles(video)
if dbrole2.get("9") == "yes":
content = discord.utils.get(ctx.guild.roles, name="Content Writer")
await ctx.author.add_roles(content)
elif dbrole2 == None:
await ctx.send(f"Hello {ctx.author.mention} Your roles are updated. Please check it out")
await ctx.author.edit(nick=str(dbrole2.get("0")))
if dbrole.get("1") == "yes":
app = discord.utils.get(ctx.guild.roles, name="App Development")
await ctx.author.add_roles(app)
if dbrole.get("2") == "yes":
print("yes")
iot = discord.utils.get(ctx.guild.roles, name="Internet Of Things(IoT)")
await ctx.author.add_roles(iot)
if dbrole.get("3") == "yes":
ml = discord.utils.get(ctx.guild.roles, name="Machine Learning")
await ctx.author.add_roles(ml)
if dbrole.get("4") == "yes":
cloud = discord.utils.get(ctx.guild.roles, name="Cloud Computing")
await ctx.author.add_roles(cloud)
if dbrole.get("5") == "yes":
mechatronics = discord.utils.get(ctx.guild.roles, name="Mechatronics")
await ctx.author.add_roles(mechatronics)
if dbrole.get("6") == "yes":
web = discord.utils.get(ctx.guild.roles, name="Web Development")
await ctx.author.add_roles(web)
if dbrole.get("7") == "yes":
design = discord.utils.get(ctx.guild.roles, name="Design Team")
await ctx.author.add_roles(design)
if dbrole.get("8") == "yes":
video = discord.utils.get(ctx.guild.roles, name="Video Editor")
await ctx.author.add_roles(video)
if dbrole.get("9") == "yes":
content = discord.utils.get(ctx.guild.roles, name="Content Writer")
await ctx.author.add_roles(content)
#============================================= Fetching token from .env
load_dotenv()
keep_alive()
robotum.run(os.getenv("TOKEN"))