-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
79 lines (66 loc) · 2.99 KB
/
main.py
File metadata and controls
79 lines (66 loc) · 2.99 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
import discord
import os
from utils.yaml_parser import admins, mods, restricted_users, whitelist_domains, whitelist_languages
from utils.validate import validate_url, validate_langs, validate_staff
from utils.messages import error_message
from dotenv import load_dotenv
load_dotenv()
guild_id = discord.Object(id=os.environ.get('guild-id'))
class MyClient(discord.Client):
def __init__(self, *, intents: discord.Intents):
super().__init__(intents=intents)
self.tree = discord.app_commands.CommandTree(self)
print(self)
async def on_command_error(self, ctx, error):
if hasattr(ctx.command, 'on_error'):
return
async def setup_hook(self):
# This copies the global commands over to your guild.
self.tree.copy_global_to(guild=guild_id)
await self.tree.sync(guild=guild_id)
print(f'Logged on as {self.user}!')
async def on_ready(self):
await self.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="Challenge Submissions"))
async def on_message(self, message):
print(f'Message from {message.author}: {message.content}')
intents = discord.Intents.default()
intents.message_content = True
client = MyClient(intents=intents)
@client.tree.command()
@discord.app_commands.check(validate_staff)
async def hello(interaction: discord.Interaction):
"""Says hello!"""
await interaction.response.send_message(f'Hi, {interaction.user.mention}')
@hello.error
async def hello_error(interaction: discord.Interaction, error):
err = error_message('You do not have permission to use this command')
await interaction.response.send_message(embed=err)
return
# --- SUBMIT COMMAND --- #
@client.tree.command()
@discord.app_commands.describe(
url='The url of your GitHub repository',
languages='The list of languages you completed in this challenge',
)
async def submit(interaction: discord.Interaction, url: str, languages: str):
"""Submit your completed challenge!"""
langs = languages.split()
if len(whitelist_domains) == 0:
err = error_message('URLs are not set up! Please check your `config.yaml`.')
await interaction.response.send_message(embed=err)
return
if len(whitelist_languages) == 0:
err = error_message('Languages are not set up! Please check your `config.yaml`.')
await interaction.response.send_message(embed=err)
return
if not validateUrl(url):
err = error_message('Invalid URL! Our currently supported URLs are: `' + ', '.join(whitelist_domains) + '`')
await interaction.response.send_message(embed=err)
return
if not validateLangs(langs):
err = error_message('Invalid Language(s)! Our currently supported languages are: `' + ', '.join(whitelist_languages) + '`')
await interaction.response.send_message(embed=err)
return
print('valid command')
await interaction.response.send_message(f'{url} + {languages}')
client.run(os.environ.get('bot-token'))