-
Notifications
You must be signed in to change notification settings - Fork 41
/
main.py
211 lines (165 loc) · 9.49 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
import discord, json, sqlite3
from datetime import datetime, timedelta
from discord import app_commands
from typing import List
from src import database
from src import utils
from src import cooldown_manager
# connect to the database
con = sqlite3.connect('accounts.db'); con.row_factory = sqlite3.Row
# discord bot stuff
bot = discord.Client(intents=discord.Intents.default())
tree = app_commands.CommandTree(bot)
config = json.load(open('config.json'))
serviceList = []
is_everything_ready = False
async def updateServices():
global serviceList
serviceList = await database.getServices(con)
return
user_cooldowns = []
@bot.event
async def on_ready():
global is_everything_ready
await tree.sync(guild=discord.Object(id=config["guild-id"]))
await updateServices()
print("Servicelist:", serviceList)
is_everything_ready = True
print("Logged in as {0.user}".format(bot))
async def service_autcom(interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]:
types = serviceList
return [
app_commands.Choice(name=service, value=service)
for service in types if current.lower() in service.lower()
]
@tree.command(name = "deleteservice", description = "(admin only)", guild=discord.Object(id=config["guild-id"]))
@app_commands.autocomplete(service=service_autcom)
async def deleteservice(interaction: discord.Interaction, service: str):
if not interaction.user.id in config['admins']:
return await interaction.response.send_message(str(config['messages']['noperms']), ephemeral=True)
if not is_everything_ready:
return await interaction.response.send_message("Bot is starting.", ephemeral=True)
db_res1 = await database.deleteService(con, service, serviceList)
if db_res1:
await updateServices()
embd=discord.Embed(
title=f"Delete Service",
description=f'{"Successfully deleted service" if db_res1 else "Error. Service doesnt exist."}',
color=int(config['colors']['success']) if db_res1 else int(config['colors']['error'])
)
embd.set_footer(text=config['messages']['footer-msg'])
return await interaction.response.send_message(embed=embd, ephemeral=True)
@tree.command(name = "gen", description = "Generate an account of your choice", guild=discord.Object(id=config["guild-id"]))
@app_commands.autocomplete(service=service_autcom)
async def gen(interaction: discord.Interaction, service: str):
global user_cooldowns
if not is_everything_ready:
return await interaction.response.send_message("Bot is starting.", ephemeral=True)
if service not in serviceList:
return await interaction.response.send_message(f'Invalid service.', ephemeral=True)
if not interaction.user.id in config['admins'] and not interaction.channel_id in config["gen-channels"]:
channel_list = [f"<#{channel}>" for channel in config["gen-channels"]]
return await interaction.response.send_message(str(config['messages']['wrongchannel']) + ', '.join(channel_list), ephemeral=True)
utl_res = await utils.does_user_meet_requirements(interaction.user.roles, config, service)
if not interaction.user.id in config['admins'] and not utl_res:
return await interaction.response.send_message(str(config['messages']['noperms']), ephemeral=True)
# Cooldown
_user_cldw = None
has_cldw = await cooldown_manager.does_user_have_cooldown(user_cooldowns, interaction.user.id)
if interaction.user.id not in config['admins'] and not has_cldw:
_user_cldw = await cooldown_manager.get_role_user_cooldown(interaction)
if _user_cldw is not None:
user_cooldowns.append(f"{interaction.user.id}:{int(_user_cldw)}")
elif has_cldw:
_data = await cooldown_manager.getCooldownData(user_cooldowns, interaction.user.id)
if _data['stillHasCooldown']:
embd=discord.Embed(title="Cooldown",description=f':no_entry_sign: {_data["formatedCooldownMsg"]}',color=config['colors']['error'])
return await interaction.response.send_message(embed=embd, ephemeral=False)
elif _data['secondsTillEnd'] == 0:
user_cooldowns.remove(f"{interaction.user.id}:{int(_data['endTime'])}")
_user_cldw = await cooldown_manager.get_role_user_cooldown(interaction)
if _user_cldw is not None:
user_cooldowns.append(f"{interaction.user.id}:{int(_user_cldw)}")
success, account = await database.getAccount(con, service)
if not success:
if _user_cldw:
user_cooldowns.remove(f"{interaction.user.id}:{int(_user_cldw)}")
return await interaction.response.send_message(f"There is no stock left.", ephemeral=True)
else:
channel = await interaction.user.create_dm()
embd=discord.Embed(
title=f"Account Generated :label: ",
description=config['messages']['altsent'] + f"\n```{account['combo']}```",
color=config['colors']['success']
)
embd.set_footer(text=config['messages']['footer-msg'],icon_url=interaction.user.avatar.url)
embd2=discord.Embed(title=f"`{service}` generated :label: ",description=':incoming_envelope: Check your DMs for the account.',color=config['colors']['success'])
embd2.set_footer(text=config['messages']['footer-msg'],icon_url=interaction.user.avatar.url)
embd2.set_image(url=config["generate-settings"]["gif-img-url"])
await channel.send(embed=embd)
return await interaction.response.send_message(embed=embd2, ephemeral=False)
@tree.command(name = "addstock", description = "Add stock to database (admin only)", guild=discord.Object(id=config["guild-id"]))
@app_commands.autocomplete(service=service_autcom)
async def addaccounts(interaction: discord.Interaction, service: str, file: discord.Attachment):
if not interaction.user.id in config['admins']:
return await interaction.response.send_message(str(config['messages']['noperms']), ephemeral=True)
if not is_everything_ready:
return await interaction.response.send_message("Bot is starting.", ephemeral=True)
if service not in serviceList:
return await interaction.response.send_message(f'Invalid service.', ephemeral=True)
try:
if not str(file.filename).endswith(".txt"):
return await interaction.response.send_message(f'You can only upload files with .txt extension', ephemeral=True)
except:
return await interaction.response.send_message(f'Error when checking file.', ephemeral=True)
if file.size > config["maximum-file-size"]:
return await interaction.response.send_message(f'Maximum file size: `{config["maximum-file-size"]} bytes`', ephemeral=True)
content = await file.read()
filtered_stock = []
dec_cont = content.decode('utf-8')
content = str(dec_cont).split("\n")
for item in content:
if len(item) > 2:
filtered_stock.append(item)
add_cnt,dupe_cnt = await database.addStock(con, service, filtered_stock, config['remove-capture-from-stock'])
return await interaction.response.send_message(f'`{add_cnt}` accounts have been added to the `{service}` database. `{dupe_cnt}` dupes found.', ephemeral=True)
@tree.command(name = "createservice", description = "(admin only)", guild=discord.Object(id=config["guild-id"]))
async def createservice(interaction: discord.Interaction, servicename: str):
if not interaction.user.id in config['admins']:
return await interaction.response.send_message(str(config['messages']['noperms']), ephemeral=True)
if not is_everything_ready:
return await interaction.response.send_message("Bot is starting.", ephemeral=True)
db_res1 = await database.createService(con, servicename, serviceList)
if db_res1:
await updateServices()
embd=discord.Embed(
title=f"Create Service",
description=f'{"Successfully created service" if db_res1 else "Error. Service already exists."}',
color=int(config['colors']['success']) if db_res1 else int(config['colors']['error'])
)
embd.set_footer(text=config['messages']['footer-msg'])
return await interaction.response.send_message(embed=embd, ephemeral=True)
@tree.command(name = "stock", description = "Get the amount of stock", guild=discord.Object(id=config["guild-id"]))
async def stock(interaction: discord.Interaction):
if not is_everything_ready:
return await interaction.response.send_message("Bot is starting.", ephemeral=True)
stock = await database.getStock(con, serviceList)
if len(stock) <= 0:
embd=discord.Embed(
title=f"Stock - 0 services",
description='There are no services to display',
color=config['colors']['stock'])
embd.set_footer(text=config['messages']['footer-msg'])
return await interaction.response.send_message(embed=embd)
filtered_stock = []
for stk in stock:
stk = (stk.split(':'))
filtered_stock.append(f"**{stk[0]}**: `{stk[1]}`")
embd=discord.Embed(
title=f"Stock - {len(filtered_stock)}",
description='\n'.join(filtered_stock),
color=config['colors']['stock']
)
embd.set_footer(text=config['messages']['footer-msg'])
return await interaction.response.send_message(embed=embd, ephemeral=config['stock-command-silent'])
bot.run(config['token'])