-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
229 lines (194 loc) · 11.2 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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import discord
from discord import app_commands
import requests
import math
import datetime
intents = discord.Intents.default()
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
# Configuration
# KeyAuth
name = ""
owner_id = ""
sellerkey = ""
# Discord
discord_token = ""
log_id = 123
allowed_id = 123 # ID of Channel where its allowed to use the Command
customer_id = 123 # ID of Role for Customers
guild_id = 123
# Give spefic Role depending on Subscription
spefic_Roles = [
{"name": "default", "value": 123},
{"name": "Main", "value": 123},
{"name": "Developer", "value": 123}
]
@tree.command(
name="register",
description="Create your Account using your License.",
guild=discord.Object(id=guild_id)
)
async def register_command(interaction, username: str, password: str, license: str):
await interaction.response.send_message(embed=discord.Embed(title="Registration is currently in progress...", color=0xff9600), ephemeral=True)
if interaction.channel.id == allowed_id:
url = f"https://keyauth.win/api/1.2/?type=init&ver=1.0&name={name}&ownerid={owner_id}"
response = requests.post(url)
data = response.json()
session_id = data.get("sessionid")
url = f"https://keyauth.win/api/1.2/?type=register&username={username}&pass={password}&key={license}&sessionid={session_id}&name={name}&ownerid={owner_id}&email=email"
response = requests.post(url)
data = response.json()
status = data["success"]
if status == True:
disc_id = interaction.user.id
url = f"https://keyauth.win/api/seller/?sellerkey={sellerkey}&type=setvar&user={username}&var=DicordID&data={disc_id}"
response = requests.post(url)
dur_seconds = data["info"]["subscriptions"][0]["timeleft"]
dur_days = dur_seconds / 86400
rounded_dur_days = math.ceil(dur_days)
dur_str = str(rounded_dur_days)
log_channel = await interaction.guild.fetch_channel(log_id)
embedComp=discord.Embed(title="Registration completed!", color=0x00ff00)
embedComp.add_field(name="Username", value=username, inline=True)
embedComp.add_field(name="Password", value=password, inline=True)
embedComp.add_field(name="License", value=license, inline=False)
embedComp.add_field(name="Duration", value=f"{dur_str} Days", inline=False)
embedComp.set_footer(text="Made by KiSki-Dev with ❤")
await interaction.followup.send(embed=embedComp, ephemeral=True)
embedLog=discord.Embed(title="Registration made!", color=0x00aaff)
embedLog.timestamp = datetime.datetime.now(datetime.UTC)
embedLog.add_field(name="Username", value=username, inline=True)
embedLog.add_field(name="Discord", value=f"<@{disc_id}>", inline=True)
embedLog.add_field(name="License", value=license, inline=False)
embedLog.add_field(name="Duration", value=f"{dur_str} Days", inline=False)
await log_channel.send(embed=embedLog)
subscription = data["info"]["subscriptions"][0]["subscription"]
for pair in spefic_Roles:
if pair["name"] == subscription:
custom_role = interaction.guild.get_role(pair["value"])
await interaction.user.add_roles(custom_role)
role = interaction.guild.get_role(customer_id) # Add Customer Role
await interaction.user.add_roles(role)
elif status == False:
error = data["message"]
error_msg = str(error)
if "License" in error_msg:
embedErr=discord.Embed(title="Registration failed!", color=0xff0000)
embedErr.add_field(name="Error:", value="This License has been already used.", inline=True)
await interaction.followup.send(embed=embedErr, ephemeral=True)
elif "password" in error_msg:
embedErr=discord.Embed(title="Registration failed!", color=0xff0000)
embedErr.add_field(name="Error:", value="This Password is too bad. Please choose another one.", inline=True)
await interaction.followup.send(embed=embedErr, ephemeral=True)
elif "taken" in error_msg:
embedErr=discord.Embed(title="Registration failed!", color=0xff0000)
embedErr.add_field(name="Error:", value="This Username is already taken.", inline=True)
await interaction.followup.send(embed=embedErr, ephemeral=True)
elif "Session" in error_msg:
embedErr=discord.Embed(title="Registration failed!", color=0xff0000)
embedErr.add_field(name="Error:", value="Please try again later.", inline=True)
await interaction.followup.send(embed=embedErr, ephemeral=True)
elif "short" in error_msg:
embedErr=discord.Embed(title="Registration failed!", color=0xff0000)
embedErr.add_field(name="Error:", value="Username too short.", inline=True)
await interaction.followup.send(embed=embedErr, ephemeral=True)
else:
embedErr=discord.Embed(title="Registration failed!", color=0xff0000)
embedErr.add_field(name="Error:", value="Unkown Error happend. Please contact the [Developer](https://github.com/KiSki-Dev)", inline=True)
await interaction.followup.send(embed=embedErr, ephemeral=True)
else:
embedErr=discord.Embed(title="Registration failed!", color=0xff0000)
embedErr.add_field(name="Error:", value="Server Error. Please try again later.", inline=True)
await interaction.followup.send(embed=embedErr, ephemeral=True)
else:
embedErr=discord.Embed(title="Wrong Channel!", color=0xff0000)
embedErr.add_field(name="Please use the correct Channel.", value=f"Please use it in <#{allowed_id}>", inline=True)
await interaction.followup.send(embed=embedErr, ephemeral=True)
@tree.command(
name="status",
description="Get the Status of Products.",
guild=discord.Object(id=guild_id)
)
@app_commands.choices(choices=[
app_commands.Choice(name="All", value="all"),
app_commands.Choice(name="Auth", value="Auth"),
app_commands.Choice(name="Main", value="Main"),
app_commands.Choice(name="Development", value="Development"),])
async def status_command(interaction, choices: app_commands.Choice[str]):
await interaction.response.send_message(embed=discord.Embed(title="Recieving Status is currently in progress...", color=0xff9600), ephemeral=True)
await client.change_presence(activity=discord.Game(name="github.com/KiSki-Dev"))
choice = choices.value
a_state, a_full_state, a_color = status("Auth")
main_state, main_full_state, main_color = status("Main")
dev_state, dev_full_state, dev_color = status("Development")
if choice == "all":
embedComp=discord.Embed(title="All Statuses!", color=0x0000ff)
embedComp.add_field(name="Auth", value=a_state, inline=False)
embedComp.add_field(name="Main", value=main_state, inline=False)
embedComp.add_field(name="Development", value=dev_state, inline=False)
await interaction.followup.send(embed=embedComp, ephemeral=True)
elif choice == "Auth":
embedComp=discord.Embed(title=a_full_state, color=a_color)
await interaction.followup.send(embed=embedComp, ephemeral=True)
elif choice == "Main":
embedComp=discord.Embed(title=main_full_state, color=main_color)
await interaction.followup.send(embed=embedComp, ephemeral=True)
elif choice == "Development":
embedComp=discord.Embed(title=dev_full_state, color=dev_color)
await interaction.followup.send(embed=embedComp, ephemeral=True)
def status(program):
p = program.lower()
url = f"http://localhost:8080/status/get/{p}" # Change to your JSON/API-URL
response = requests.get(url)
data = response.json()
status = data["status"]
if status.lower() == "offline":
full_state = f"🔴 : {program} is Offline."
state = "🔴 : Offline"
color = 0xff0000
elif status.lower() == "online":
full_state = f"🟢 : {program} is Online."
state = "🟢 : Online"
color = 0x00ff00
elif status.lower() == "testing":
full_state = f"🟠 : We are Testing {program} at the moment."
state = "🟠 : Testing"
color = 0xff6400
elif status.lower() == "updating":
full_state = f"🟠 : We are Updating {program} at the moment."
state = "🟠 : Updating"
color = 0xff6400
elif status.lower() == "unkown":
full_state = f"🟠 : We are checking the Status of {program} at the moment."
color = 0xff6400
else:
full_state = f"🔴 : A Error happend while recieving the Status of {program}."
state = "🔴 : Unkown"
color = 0xff0000
return state, full_state, color
embedRegister=discord.Embed(title="Help - Register", color=0x009dff)
embedRegister.add_field(name="Create a Account", value="using the Register Command.", inline=False)
embedRegister.add_field(name="Requirements:", value="Unique Username, Good Password, Working License", inline=False)
embedRegister.add_field(name="Instructions", value='Write "**/register**". You should get a Suggestion for the Command. Enter your desired Username, then enter a strong Password. Now you enter your bought License-Key.', inline=False)
embedRegister.add_field(name="Lost Login Data?", value="If you lost any Login-Data or you want to reset your HWID, then contact our Support. We can proof that you actually own a Account.", inline=True)
embedStatus=discord.Embed(title="Help - Status", color=0xff00d0)
embedStatus.add_field(name="Get the Status", value="using the Status Command.", inline=False)
embedStatus.add_field(name="You cant login? Or the Cheat doesnt work?", value="Then you should run the Status Command. Using the Status Command you can see what in our System works and what does not.", inline=False)
embedMore=discord.Embed(title="Help - More", color=0xff9600)
embedMore.add_field(name="Any Other Informations", value="you can see here.", inline=False)
embedMore.add_field(name="Found a Bug?", value='If you found a Bug please directly report it to the Support or the [Bot Developer "KiSki-Dev"](https://github.com/KiSki-Dev).', inline=False)
embedMore.add_field(name="Like the Bot?", value='If you like the Bot, the Bot-Developer "KiSki-Dev" would really appreciate, if you check out his [GitHub](https://github.com/KiSki-Dev).', inline=False)
embedMore.add_field(name="Missing some Features?", value="We are working to constantly adding and upgrading Features. If you miss any Feature, contact the Support and tell them your Idea.", inline=False)
@tree.command(
name="help",
description="List all Commands.",
guild=discord.Object(id=guild_id))
async def help_command(interaction):
await interaction.response.send_message(embed=embedRegister, ephemeral=True)
await interaction.followup.send(embed=embedStatus, ephemeral=True)
await interaction.followup.send(embed=embedMore, ephemeral=True)
@client.event
async def on_ready():
await tree.sync(guild=discord.Object(id=guild_id))
print("Bot is ready!")
client.run(discord_token)