-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
161 lines (134 loc) · 5.33 KB
/
main.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
from turtle import color
import discord
import json
import random
import asyncio
import time
from discord.ext import commands
from discord.utils import get
from datetime import datetime, timedelta
from discord_components import DiscordComponents, Button, ButtonStyle, Select, SelectOption
from csgo_api import CSGOStats
from embed_bot import Embed
import keep_alive
async def get_prefix(bot, message):
guild = message.guild
with open("extra.json", "r") as ex:
data = json.load(ex)
for i in range(len(data["prefix"])):
if list(data["prefix"][i].keys())[0] == str(guild.id):
prefix = data["prefix"][i][str(guild.id)]
if guild:
return prefix
else:
return "cs!"
client = commands.Bot(command_prefix=get_prefix, help_command=None)
DiscordComponents(client)
@client.event
async def on_ready() :
time=datetime.now()
print("------\nBot Connecté\nRappelBump\n"+str(client.user.id)+"\nBot lancé le "+str(time.strftime("%d-%m-%Y à %H:%M:%S")+"\n------"))
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="cs!help"))
@client.command()
@commands.has_permissions(manage_guild=True)
async def prefix(ctx, prefix):
with open("extra.json", "r") as ex:
data = json.load(ex)
for i in range(len(data["prefix"])):
if list(data["prefix"][i].keys())[0] == str(ctx.guild.id):
data["prefix"][i][str(ctx.guild.id)] = prefix
break
with open("extra.json", "w") as ex:
json.dump(data, ex)
await ctx.send(embed=discord.Embed(title=f"Le nouveau préfix est {prefix}"))
@commands.cooldown(1, 2, commands.BucketType.user)
@client.command()
async def help(ctx):
with open("extra.json", "r") as ex:
data = json.load(ex)
for i in range(len(data["prefix"])):
if list(data["prefix"][i].keys())[0] == str(ctx.message.guild.id):
prefixe = data["prefix"][i][str(ctx.guild.id)]
break
embed = discord.Embed(
title="__**Liste des commandes**__",
description=f"Prefix du bot = `{prefixe}` \n\n **Serveur** (Staff Only) : \n\n`prefix`",
colour=5213)
await ctx.send(embed=embed)
@client.command()
async def profil(ctx, *, name):
STATS = CSGOStats(name).informations_profil
await ctx.send(embed = Embed.profil_stats(name, STATS))
@client.command()
async def weapons(ctx, *, name):
global name_to_give_stats
global embed
STATS = CSGOStats(name)
emojiPage2 = client.get_emoji(983369471618084916)
name_to_give_stats= name
embed = await ctx.send(embed = Embed().weapon_stats(name, STATS.informations_weapons, STATS.informations_profil["avatar"]), components=[[
Button(style=ButtonStyle.grey,
label="Page 2",
emoji=emojiPage2)]])
@client.command()
async def stats(ctx, *, name):
await ctx.send(
f"Menu des Statistiques de {name}",
components=[
Select(
placeholder="Quelles statistiques souhaiteriez-vous voir ?",
options=[
SelectOption(label="Profil", value="Profil"),
SelectOption(label="Armes", value="Armes"),
SelectOption(label="Maps", value="Maps")],
custom_id="select1")])
interaction = await client.wait_for("select_option", check=lambda inter: inter.custom_id == "select1")
STATS = CSGOStats(name)
if interaction.values[0] == "Profil":
await ctx.send(embed = Embed.profil_stats(name, STATS.informations_profil))
elif interaction.values[0] == "Armes":
global name_to_give_stats
global embed
STATS = CSGOStats(name)
emojiPage2 = client.get_emoji(983369471618084916)
name_to_give_stats= name
embed = await ctx.send(embed = Embed().weapon_stats(name, STATS.informations_weapons, STATS.informations_profil["avatar"]), components=[[
Button(style=ButtonStyle.grey,
label="Page 2",
emoji=emojiPage2)]])
elif interaction.values[0] == "Maps":
await ctx.send(embed = Embed.map_stats(name, STATS))
@client.event
async def on_guild_join(guild):
with open("extra.json", "r") as ex:
data = json.load(ex)
data["prefix"].append({str(guild.id): "cs!"})
with open("extra.json", "w") as ex:
json.dump(data, ex)
@client.event
async def on_button_click(res):
if res.component.label == "Page 2":
STATS = CSGOStats(name_to_give_stats)
emojiPage1 = client.get_emoji(983367231352234034)
await embed.edit(embed = Embed().weapon_stats2(name_to_give_stats, STATS.informations_weapons, STATS.informations_profil["avatar"]), components=[[
Button(style=ButtonStyle.grey,
label="Page 1",
emoji=emojiPage1)]])
elif res.component.label == "Page 1":
STATS = CSGOStats(name_to_give_stats)
emojiPage2 = client.get_emoji(983369471618084916)
await embed.edit(embed = Embed().weapon_stats(name_to_give_stats, STATS.informations_weapons, STATS.informations_profil["avatar"]), components=[[
Button(style=ButtonStyle.grey,
label="Page 2",
emoji=emojiPage2)]])
"""@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("<:pepesmile:828677897288024154> Vous n'avez pas les permissions pour effectuer cette commande !")
else:
Embeds = Embed()
Embed_Errors = {
"prefix": Embeds.ErrorPrefix}
await ctx.send(embed=Embed_Errors[ctx.command.qualified_name])"""
keep_alive.keep_alive()
client.run("OTgzMTI2MjAyODc1MjY5MTQ0.GO2L27.3aMD-7u2mWCt_wUOeQc6mKq1zxzim7WDjoWBsQ")