-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathava.py
207 lines (189 loc) · 7.46 KB
/
ava.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
import os
import asyncio
import discord
import random
from dotenv import load_dotenv
from discord.ext import commands
from discord.ext.commands import CommandNotFound
from script.log import log_emit
from script.pushemail import sendemails
load_dotenv()
server = os.getenv("SERVER")
TOKEN = os.getenv('DISCORD_TOKEN')
DEPARTMENT_MESSAGE = int(os.getenv("DEPARTMENT_MESSAGE"))
EMAIL_MESSAGE = int(os.getenv("EMAIL_MESSAGE"))
DEPARTMENT_CHANNEL = int(os.getenv("DEPARTMENT_CHANNEL"))
LOG_CHANNEL = int(os.getenv("LOG_CHANNEL"))
DEBUG = (os.getenv("DEBUG","") != "False" )
AUTHOR = 664161180121825301
DEPARTMENTS = [
('🤖', 'Competitive Coding'),
('🦸', 'Development'),
('👨💻', 'AI'),
('🕵️', 'Security')
]
def match(a, b):
l = min(len(a), len(b))
a1 = a[:l].lower()
b1 = b[:l].lower()
if(a1 == b1):
return True
return False
intents = discord.Intents.default()
intents.members = True
#client = discord.Client()
bot = commands.Bot(
command_prefix='.',
description='Coding Club IIT Jammu Discord BOT',
case_insensitive=True ,
intents = intents
)
bot.load_extension('script.verify')
bot.load_extension('script.info')
bot.load_extension('script.ratings')
bot.load_extension('script.admin')
@bot.event
async def on_ready():
global logs, dep_channel, guild, notify
dep_channel = bot.get_channel(DEPARTMENT_CHANNEL)
logs = log_emit(LOG_CHANNEL, bot, DEBUG)
notify = sendemails(bot, DEBUG)
guild = bot.get_guild(int(server))
role = discord.utils.get(guild.roles, name = 'Verified')
await dep_channel.set_permissions(role, read_messages=True )
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=".help 💗"))
await logs.print(f'{bot.user.mention} has connected to Discord!')
print("connected")
@bot.event
async def on_member_join(member):
await member.create_dm()
await member.dm_channel.send(
f'Hi {member.name}, welcome to Coding Club IIT Jammu Discord server. Pls Verify using .verify command followed by Name in quotes and entry number'
)
await logs.print(f'{member.mention} joined Server!')
@bot.command()
async def leave(ctx):
if(ctx.message.author.id != AUTHOR):
return
# Pausing self dept selection flow
# role = discord.utils.get(guild.roles, name = 'Verified')
# await dep_channel.set_permissions(role, read_messages=False )
await ctx.send('Leaving server. BYE!')
await logs.print(f'{bot.user.mention} leaving Server! command from {ctx.author}.')
await bot.close()
@bot.command()
@commands.cooldown(1, 15, commands.BucketType.user)
async def id(ctx):
await ctx.send(f"{ctx.author.id}")
@bot.event
async def on_raw_reaction_add(payload):
Rating_cog = bot.get_cog("Ratings")
await Rating_cog.increaseXP(payload.user_id, 1, False)
if(payload.message_id == DEPARTMENT_MESSAGE):
emoji = payload.emoji.name
member = payload.member
for i in DEPARTMENTS:
if(i[0] == emoji):
role = discord.utils.get(guild.roles, name=i[1])
if(role in member.roles):
return print(f"{payload.member} already assigned {role}")
await member.add_roles(role)
return await logs.print(f"added {payload.member.mention} to {role}")
print("other emoji")
elif(payload.message_id == EMAIL_MESSAGE):
emoji = payload.emoji.name
member = payload.member
correct = '✅'
if(emoji == correct):
role = discord.utils.get(guild.roles, name= "Receive Emails")
if(role in member.roles):
return print(f"{payload.member} already subscribed to Emails")
await member.add_roles(role)
return await logs.print(f"added {payload.member.mention} to {role}")
@bot.event
async def on_raw_reaction_remove(payload):
Rating_cog = bot.get_cog("Ratings")
await Rating_cog.increaseXP(payload.user_id, -1, False)
if(payload.message_id == DEPARTMENT_MESSAGE):
emoji = payload.emoji.name
user_id = payload.user_id
member = guild.get_member(user_id)
for i in DEPARTMENTS:
if(i[0] == emoji):
role = discord.utils.get(guild.roles, name=i[1])
if(role in member.roles):
await member.remove_roles(role)
return await logs.print(f"{member.mention} removed from {role}")
return print(f"{member} not assigned {role}")
return print("other emoji")
elif(payload.message_id == EMAIL_MESSAGE):
emoji = payload.emoji.name
user_id = payload.user_id
member = guild.get_member(user_id)
correct = '✅'
if(emoji == correct):
role = discord.utils.get(guild.roles, name= "Receive Emails")
if(role in member.roles):
await member.remove_roles(role)
return await logs.print(f"{member.mention} removed from {role}")
return print(f"{payload.member} already unsubscribed to Emails")
return print("other emoji")
@bot.event
async def on_message(message):
if message.author.bot:
return
if isinstance(message.channel, discord.channel.TextChannel): #ONLY GUILD messages
if("@here" in message.content):
core_role = discord.utils.get(guild.roles, name="Core Team")
if(core_role in message.author.roles):
await notify.send(message)
#increase XP
if(message.channel.category_id != int(os.getenv("CORE_CAT"))):
msg_got = message.content
if((match(msg_got, ".rating") or match(msg_got, ".ranklist")) == 0):
incXP = random.randint(3,5)
if(msg_got[0] in [".", "-", "!" ]):
incXP = 1
Rating_cog = bot.get_cog("Ratings")
await Rating_cog.increaseXP(message.author.id, incXP)
await bot.process_commands(message)
'''
@bot.command()
async def startup(ctx):
if(ctx.message.author.id != AUTHOR):
return
start_txt = 'Join the channels by reacting with emoji of respective department'
for i in DEPARTMENTS:
start_txt = start_txt + "\n" + i[0] + " " + i[1]
msg = await ctx.send(start_txt)
guild = bot.get_guild(int(server))
for i in DEPARTMENTS:
emoji = i[0]
await msg.add_reaction(emoji)
correct = '✅'
desc = f"All messages triggered by Core team will be forwarded to your organization Email. You can Subscribe by reacting {correct} and unsubscribe by removing same reaction"
em = discord.Embed(title="Subscribe for emails", description=desc)
msg = await ctx.send(embed=em)
await msg.add_reaction(correct)
'''
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
msg = 'This command is ratelimited, please try again in {:.2f}s'.format(error.retry_after)
await ctx.send(msg)
elif isinstance(error, CommandNotFound):
user_m = '{0.author.mention} '.format(ctx)
msg_s = "Invalid Command"
msg_s = user_m + msg_s
await ctx.send(msg_s)
elif isinstance(error, commands.errors.MissingRole ):
await ctx.send("Don`t have permission")
else:
raise error
@bot.command()
@commands.has_role('Verified')
async def avatar(ctx, avamember : discord.Member=None):
userAvatarUrl = avamember.avatar_url
print(userAvatarUrl)
await ctx.send(userAvatarUrl)
bot.run(TOKEN)