-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
158 lines (124 loc) · 4.28 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
import json
import datetime
import asyncio
import aiohttp
import discord
from discord.utils import get
from discord.ext import commands
from auth import *
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
config = json.loads(
open('./data/config.json').read()
)
client = commands.Bot(
command_prefix=config['prefix']
)
@client.event
async def on_ready():
print('Bot is running - main server')
@client.event
async def on_command_error(ctx, error):
embed = discord.Embed(
title="Oops shit happened",
description=f"Oops error: {error}",
color=0x7289DA
)
await ctx.send(embed=embed)
@client.command()
async def stock(ctx):
products = []
async with aiohttp.ClientSession() as session:
async with session.get(
'https://autobuy.io/api/Products',
headers = {'APIKey': config['api_key']}
) as response:
content = await response.json()
for ids in content['products']:
products.append(
f'**Product:** {ids["name"]}\n**Price:** ${ids["price"]}\n**Stock:** {ids["stockCount"]}\n\n'
)
embed = discord.Embed(
title="Lists of products",
description=''.join(products),
color=0x7289DA
)
await ctx.send(embed=embed)
@client.command()
@commands.has_role(config['admin'])
async def remove(ctx, product_id):
async with aiohttp.ClientSession() as session:
async with session.delete(
'https://autobuy.io/api/Product',
data = 'id=' + product_id,
headers = {
'APIKey': config['api_key'],
'Content-Type': 'application/x-www-form-urlencoded'
}
) as response:
content = await response.text()
if 'Authorization failed or the product does not exist.' in content:
embed = discord.Embed(
title="Could not find product",
description=f"Could not find product or api key is not valid",
color=0x7289DA
)
await ctx.send(embed=embed)
else:
embed = discord.Embed(
title="Product has been removed!",
color=0x7289DA
)
await ctx.send(embed=embed)
@client.command()
async def redeem(ctx, order_id):
role = ctx.guild.get_role(config['customer'])
result = await check_redeemed(order_id)
if result == True:
embed = discord.Embed(
title="This order id has already been redeemed",
color=0x7289DA
)
else:
result = await check_order(order_id)
if result == 'Order not found':
embed = discord.Embed(
title="Order id is not valid",
description=f"Order id {order_id} is not valid.",
color=0x7289DA
)
else:
await ctx.message.author.add_roles(role)
await use_orderid(order_id)
embed = discord.Embed(
title="Order id found!",
description=f"Role has been added.",
color=0x7289DA
)
await ctx.send(embed=embed)
@client.command()
@commands.has_role(config['admin'])
async def check(ctx, order_id):
custom_feilds = []
result = await check_order(order_id)
if result != 'Order not found':
for feilds in result['customFields']:
custom_feilds.append(f"{feilds['name']}: {feilds['value']}\n")
embed = discord.Embed(
title="Order has been found!",
color=0x7289DA
)
embed.add_field(name="Complete:",value=result['isComplete'],inline=True)
embed.add_field(name="Cost:",value=result['total'],inline=True)
embed.add_field(name="Product:",value=result['productName'],inline=False)
embed.add_field(name="Email:",value=result['email'],inline=True)
embed.add_field(name="Ip address:",value=result['ipAddress'],inline=True)
embed.add_field(name="Custom feilds:",value=''.join(custom_feilds),inline=False)
else:
embed = discord.Embed(
title=result,
color=0x7289DA
)
await ctx.send(embed=embed)
if __name__ == '__main__':
client.run(config['token'])