-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
105 lines (81 loc) · 3.11 KB
/
main.py
File metadata and controls
105 lines (81 loc) · 3.11 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
# coding: utf8
import discord
from discord.ext import commands
import constants
import sys
import os
from dotenv import load_dotenv
from keep_alive import keep_alive
from datetime import datetime
intents = discord.Intents.all()
intents.members = True
bot = commands.Bot(command_prefix="!", intents=intents)
console = sys.stdout
#detecter l'allumage du bot
@bot.event
async def on_ready():
print("Successfully connected !")
servernb = str(len(bot.guilds))
await bot.change_presence(status=discord.Status.online, activity=discord.Game("serving "+servernb+" servers"))
@bot.event
async def on_member_join(member):
channel = member.guild.system_channel
serveur = member.guild.id
if channel is not None:
await channel.send('Welcome in the server {0.mention}.'.format(member))
#commande test
@bot.command()
async def ping(ctx):
"""
A small command to see if the bot is alive
"""
await ctx.send("pong")
@bot.command()
async def python(ctx):
"""
A command to execute python scripts.
First, call the command, and wait for a bot waiting message.
Second, write your code. You can choose to write it with or without the python code markdown\n(\`\`\`python\n code \n \`\`\`)\n
"""
sys.stdout = console
channel = ctx.channel
authorid = ctx.author.id
def check(m):
return m.channel == channel and m.author.id == authorid
messagebot = await ctx.send(constants.send_wait_msg)
prgm = await bot.wait_for('message', check=check)
await messagebot.delete(delay=2)
await ctx.message.delete(delay=2)
if prgm.content.startswith("```"):
prgm.content = prgm.content.replace("```python","")
prgm.content = prgm.content.replace("```","")
with open("input.py","w") as input_file:
input_file.write(prgm.content)
os.system("wandbox-python3 run input.py > retour.txt")
with open("retour.txt", "r") as output_file:
retour_txt = output_file.read()
if not retour_txt.startswith("signal: Killed"):
retour_txt = retour_txt[17:]
else:
retour_txt = "Your program is too slow"
try:
message = await ctx.send("```python\n"+retour_txt+"```")
except discord.errors.HTTPException:
with open("retour.txt", "r") as output_file:
message = await ctx.send("```The output is more than 2000 characters. Please consider shorting it.```", file=discord.File(output_file,filename=datetime.now().strftime("%d %b %Y. %H:%M:%S.txt")))
await message.add_reaction(constants.emotrash)
@bot.event
async def on_raw_reaction_add(payload):
channel = bot.get_channel(payload.channel_id)
messageReaction = await channel.fetch_message(payload.message_id)
if messageReaction.author.id == constants.botid and payload.user_id != constants.botid:
if payload.emoji.name == constants.emotrash:
await messageReaction.delete()
@bot.event
async def on_message(ctx):
servernb = str(len(bot.guilds))
await bot.change_presence(status=discord.Status.online, activity=discord.Game("serving "+servernb+" servers"))
load_dotenv()
token = os.getenv('TOKEN')
keep_alive()
bot.run(token)