Skip to content

Commit

Permalink
Merge pull request #44 from Skyward-Brawlhalla/refactor-some
Browse files Browse the repository at this point in the history
Refactor main.py, except for add_link
  • Loading branch information
CrossyChainsaw authored Sep 1, 2022
2 parents 6a82491 + d901c58 commit 9c97fdc
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 70 deletions.
Binary file modified __pycache__/command_clan_list.cpython-38.pyc
Binary file not shown.
Binary file added __pycache__/command_status.cpython-38.pyc
Binary file not shown.
88 changes: 87 additions & 1 deletion command_link_add.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,92 @@
import json

import discord

async def get_add_link():
msg = '*Added Link*'
return msg

class User:
def __init__(self, brawlhalla_id, brawlhalla_name, discord_id,
discord_name):
self.brawlhalla_id = brawlhalla_id
self.brawlhalla_name = brawlhalla_name
self.discord_id = discord_id
self.discord_name = discord_name

async def add_link(bot, ctx, brawlhalla_id, discord_id, embed_color):
# first check if the entry already exists
with open('./data_link_' + ctx.guild.name + '.json') as data:
link_data = json.load(data)
new_entry = True
for user in link_data:
if str(user['brawlhalla_id']) == str(brawlhalla_id):
await ctx.send('brawlhalla_id: ' + brawlhalla_id +
' has already been linked')
new_entry = False
break
if str(user['discord_id']) == str(discord_id):
await ctx.send('discord_id: ' + discord_id +
' has already been linked')
new_entry = False
break

brawlhalla_name = 'blank'
discord_name = 'blank'

# check if ids are valid
if new_entry == True:
valid_brawlhalla_id = False
valid_discord_id = False
# check clan id
with open('./data_clan_' + ctx.guild.name + '.json') as data:
clan_data = json.load(data)
for member in clan_data['clan']:
if str(member['brawlhalla_id']) == str(brawlhalla_id):
valid_brawlhalla_id = True
brawlhalla_name = member['name']
# check dc id
with open('./data_discord_' + ctx.guild.name + '.json') as data:
discord_data = json.load(data)
for account in discord_data:
if str(account['id']) == str(discord_id):
valid_discord_id = True
discord_name = account['name']

# if entry ids are valid, add it
if ((valid_brawlhalla_id == True) and (valid_discord_id == True)
and (new_entry == True)):

await ctx.send('Are you sure you want to add the following link?,')
await ctx.send(
embed=discord.Embed(description='**brawlhalla_id**: ' +
brawlhalla_id + '\n**brawlhalla_name**: ' +
brawlhalla_name + '\n**discord_id**: ' +
discord_id + '\n**discord_name**: ' +
discord_name,
color=embed_color))
await ctx.send('Send `y` to confirm or `n` to cancel.')
msg = await bot.wait_for('message', check=check)
if msg.content == 'y':
user = User(brawlhalla_id, brawlhalla_name, discord_id,
discord_name)
users = []
users = link_data
users.append(user.__dict__)
with open('./data_link_' + ctx.guild.name + '.json', 'w') as f:
some_data = json.dump(users, f)

embed = discord.Embed(
description='**Added Following Link**\n**brawlhalla_id**: ' +
brawlhalla_id + '\n**brawlhalla_name**: ' + brawlhalla_name +
'\n**discord_id**: ' + discord_id + '\n**discord_name**: ' +
discord_name,
color=embed_color)
await ctx.send(embed=embed)
elif msg.content == 'n':
await ctx.send('*Process Canceled*')
else:
await ctx.send('Invalid answer, process canceled')
else:
await ctx.send(
"There was an error while trying to make the link. One of the following ids doesn't exist\n`discord_id: "
+ discord_id + '`\n`brawlhalla_id: ' + brawlhalla_id + '`')
50 changes: 50 additions & 0 deletions command_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import discord
from command_link_list import get_not_linked_brawlhalla_list, get_not_linked_discord_list, get_left_players
from command_clan_update import update_clan_data
from command_discord_update import update_discord_data

async def get_status(ctx, embed_color):
# send loading message
msg_loading_data = await ctx.send('_Loading Data..._')

# update all data
await update_discord_data(ctx)
update_clan_data(ctx)

# setup all embeds and their corresponding information
msg_list2 = await get_not_linked_brawlhalla_list(ctx)
embed_not_linked_brawlhalla_list_first = discord.Embed(
description=msg_list2[0], color=embed_color)
embed_not_linked_brawlhalla_list_last = discord.Embed(
description=msg_list2[1], color=embed_color)

msg_list3 = await get_not_linked_discord_list(ctx)
embed_not_linked_discord_list_first = discord.Embed(
description=msg_list3[0], color=embed_color)
embed_not_linked_discord_list_last = discord.Embed(
description=msg_list3[1], color=embed_color)

msg_left_players = await get_left_players(ctx)
embed_left_players = discord.Embed(description=msg_left_players,
color=embed_color)

# send embeds
# send not linked brawlhalla accounts
await ctx.channel.send(embed=embed_not_linked_brawlhalla_list_first)
try:
await ctx.channel.send(embed=embed_not_linked_brawlhalla_list_last)
except:
print('less than 26 entries')

# send not linked discord accounts
await ctx.channel.send(embed=embed_not_linked_discord_list_first)
try:
await ctx.channel.send(embed=embed_not_linked_discord_list_last)
except:
print('less than 26 entries')

# send all players who left the clan
await ctx.send(embed=embed_left_players)

# delete loading message
await msg_loading_data.delete()
2 changes: 1 addition & 1 deletion data_clan_Dair.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"clan_id": 1357965, "clan_name": "Dair", "clan_create_date": 1609151553, "clan_xp": "1413617", "clan": [{"brawlhalla_id": 6746620, "name": "sgrape", "rank": "Leader", "join_date": 1656780578, "xp": 32909}, {"brawlhalla_id": 4070196, "name": "Goofy", "rank": "Officer", "join_date": 1656782361, "xp": 49227}, {"brawlhalla_id": 23890819, "name": "Benjihypp\u00c3\u00a4\u00c3\u00a4j\u00c3\u00a4", "rank": "Member", "join_date": 1656786527, "xp": 17689}, {"brawlhalla_id": 24664406, "name": "Rimuru", "rank": "Member", "join_date": 1656792002, "xp": 18902}, {"brawlhalla_id": 27930713, "name": "Madison", "rank": "Member", "join_date": 1656840626, "xp": 23594}, {"brawlhalla_id": 35664307, "name": "yum", "rank": "Member", "join_date": 1656842131, "xp": 40286}, {"brawlhalla_id": 59561496, "name": "Memory", "rank": "Member", "join_date": 1656848208, "xp": 32705}, {"brawlhalla_id": 29109995, "name": "SiLver", "rank": "Member", "join_date": 1656857493, "xp": 21097}, {"brawlhalla_id": 34242870, "name": "$now?!", "rank": "Member", "join_date": 1656864319, "xp": 70148}, {"brawlhalla_id": 43401640, "name": "FuuuX", "rank": "Member", "join_date": 1656873217, "xp": 27209}, {"brawlhalla_id": 8948682, "name": "La Planta", "rank": "Member", "join_date": 1656875188, "xp": 27279}, {"brawlhalla_id": 7974814, "name": "ZAW;", "rank": "Member", "join_date": 1656880761, "xp": 19879}, {"brawlhalla_id": 9569848, "name": "1dimensionalbucket", "rank": "Member", "join_date": 1656883554, "xp": 14174}, {"brawlhalla_id": 35710376, "name": "Camila.", "rank": "Member", "join_date": 1656945111, "xp": 4050}, {"brawlhalla_id": 3711805, "name": "flower", "rank": "Member", "join_date": 1656968084, "xp": 33899}, {"brawlhalla_id": 454666, "name": "Zabulon", "rank": "Member", "join_date": 1657047191, "xp": 17404}, {"brawlhalla_id": 57482158, "name": "walter white", "rank": "Member", "join_date": 1657053675, "xp": 28048}, {"brawlhalla_id": 7142017, "name": "Julian", "rank": "Member", "join_date": 1657123140, "xp": 24097}, {"brawlhalla_id": 40321889, "name": "peon", "rank": "Member", "join_date": 1657370066, "xp": 37888}, {"brawlhalla_id": 5671092, "name": "Skeldra", "rank": "Member", "join_date": 1657473993, "xp": 17824}, {"brawlhalla_id": 9626815, "name": "Rasdos", "rank": "Member", "join_date": 1657476377, "xp": 40923}, {"brawlhalla_id": 830910, "name": "Dagmar <3", "rank": "Officer", "join_date": 1657568746, "xp": 32962}, {"brawlhalla_id": 7220395, "name": "Kami", "rank": "Member", "join_date": 1657578939, "xp": 17411}, {"brawlhalla_id": 9070717, "name": "TragicX7", "rank": "Member", "join_date": 1657581252, "xp": 15314}, {"brawlhalla_id": 7846170, "name": "Joryes", "rank": "Member", "join_date": 1657615456, "xp": 17355}, {"brawlhalla_id": 7294526, "name": "Mr_Gaming202", "rank": "Member", "join_date": 1658169785, "xp": 27654}, {"brawlhalla_id": 10352807, "name": "Doku", "rank": "Member", "join_date": 1658170826, "xp": 14199}, {"brawlhalla_id": 8275242, "name": "Jhonny", "rank": "Member", "join_date": 1658174887, "xp": 20523}, {"brawlhalla_id": 5503396, "name": "MRB", "rank": "Member", "join_date": 1658345270, "xp": 34218}, {"brawlhalla_id": 7159263, "name": "PCS | Shadra - Baguette senpai", "rank": "Member", "join_date": 1658395590, "xp": 28628}, {"brawlhalla_id": 3013356, "name": "oszcar", "rank": "Member", "join_date": 1658856944, "xp": 49421}, {"brawlhalla_id": 2600667, "name": "SamiGigi", "rank": "Member", "join_date": 1658948471, "xp": 8302}, {"brawlhalla_id": 69630716, "name": "sH [s\u00c4\u0081j]", "rank": "Member", "join_date": 1659274583, "xp": 59163}, {"brawlhalla_id": 4639959, "name": "seidai", "rank": "Member", "join_date": 1659980209, "xp": 4633}, {"brawlhalla_id": 26084391, "name": ".diline", "rank": "Member", "join_date": 1660910171, "xp": 6931}, {"brawlhalla_id": 70022787, "name": "twitch.tv/ma2st4er5", "rank": "Officer", "join_date": 1660934058, "xp": 10209}, {"brawlhalla_id": 5111230, "name": "WelFe", "rank": "Member", "join_date": 1660938600, "xp": 4648}, {"brawlhalla_id": 7364605, "name": "CrossySpeedrun", "rank": "Member", "join_date": 1660940056, "xp": 5379}, {"brawlhalla_id": 26417667, "name": "Dobleh #Lidia", "rank": "Member", "join_date": 1660940976, "xp": 5328}, {"brawlhalla_id": 9048248, "name": "Lil Liser <3", "rank": "Member", "join_date": 1660989573, "xp": 3145}, {"brawlhalla_id": 83366016, "name": "twitch.tv/WhisperBH", "rank": "Member", "join_date": 1661004909, "xp": 10648}, {"brawlhalla_id": 1209176, "name": "woop!?", "rank": "Member", "join_date": 1661021682, "xp": 5214}, {"brawlhalla_id": 3764805, "name": "Lil'Fox <3", "rank": "Member", "join_date": 1661104096, "xp": 6387}, {"brawlhalla_id": 3794093, "name": "MrEmpanadilla19", "rank": "Member", "join_date": 1661640242, "xp": 6393}, {"brawlhalla_id": 3995547, "name": "iiTzHairu!?", "rank": "Member", "join_date": 1661858269, "xp": 427}, {"brawlhalla_id": 3221385, "name": "the neutral duck (Eldad)", "rank": "Member", "join_date": 1661870719, "xp": 312}, {"brawlhalla_id": 42572878, "name": "xFabio", "rank": "Member", "join_date": 1661871499, "xp": 1213}]}
{"clan_id": 1357965, "clan_name": "Dair", "clan_create_date": 1609151553, "clan_xp": "1433572", "clan": [{"brawlhalla_id": 6746620, "name": "sgrape", "rank": "Leader", "join_date": 1656780578, "xp": 33229}, {"brawlhalla_id": 4070196, "name": "Goofy", "rank": "Officer", "join_date": 1656782361, "xp": 49227}, {"brawlhalla_id": 23890819, "name": "Benjihypp\u00c3\u00a4\u00c3\u00a4j\u00c3\u00a4", "rank": "Member", "join_date": 1656786527, "xp": 17689}, {"brawlhalla_id": 24664406, "name": "Rimuru", "rank": "Member", "join_date": 1656792002, "xp": 18917}, {"brawlhalla_id": 27930713, "name": "Madison", "rank": "Member", "join_date": 1656840626, "xp": 24160}, {"brawlhalla_id": 35664307, "name": "yum", "rank": "Member", "join_date": 1656842131, "xp": 40804}, {"brawlhalla_id": 59561496, "name": "Memory", "rank": "Member", "join_date": 1656848208, "xp": 33616}, {"brawlhalla_id": 29109995, "name": "SiLver", "rank": "Member", "join_date": 1656857493, "xp": 21429}, {"brawlhalla_id": 34242870, "name": "$now?!", "rank": "Member", "join_date": 1656864319, "xp": 71183}, {"brawlhalla_id": 43401640, "name": "FuuuX", "rank": "Member", "join_date": 1656873217, "xp": 27374}, {"brawlhalla_id": 8948682, "name": "La Planta", "rank": "Member", "join_date": 1656875188, "xp": 27279}, {"brawlhalla_id": 7974814, "name": "ZAW;", "rank": "Member", "join_date": 1656880761, "xp": 20381}, {"brawlhalla_id": 9569848, "name": "1dimensionalbucket", "rank": "Member", "join_date": 1656883554, "xp": 14174}, {"brawlhalla_id": 35710376, "name": "Camila.", "rank": "Member", "join_date": 1656945111, "xp": 4050}, {"brawlhalla_id": 3711805, "name": "flower", "rank": "Member", "join_date": 1656968084, "xp": 33899}, {"brawlhalla_id": 454666, "name": "Zabulon", "rank": "Member", "join_date": 1657047191, "xp": 17456}, {"brawlhalla_id": 57482158, "name": "walter white", "rank": "Member", "join_date": 1657053675, "xp": 28452}, {"brawlhalla_id": 7142017, "name": "Julian", "rank": "Member", "join_date": 1657123140, "xp": 24253}, {"brawlhalla_id": 40321889, "name": "peon", "rank": "Member", "join_date": 1657370066, "xp": 38312}, {"brawlhalla_id": 5671092, "name": "Skeldra", "rank": "Member", "join_date": 1657473993, "xp": 17824}, {"brawlhalla_id": 9626815, "name": "Rasdos", "rank": "Member", "join_date": 1657476377, "xp": 41478}, {"brawlhalla_id": 830910, "name": "Dagmar <3", "rank": "Officer", "join_date": 1657568746, "xp": 33237}, {"brawlhalla_id": 7220395, "name": "Kami", "rank": "Member", "join_date": 1657578939, "xp": 18132}, {"brawlhalla_id": 9070717, "name": "TragicX7", "rank": "Member", "join_date": 1657581252, "xp": 15314}, {"brawlhalla_id": 7846170, "name": "Joryes", "rank": "Member", "join_date": 1657615456, "xp": 17355}, {"brawlhalla_id": 7294526, "name": "Mr_Gaming202", "rank": "Member", "join_date": 1658169785, "xp": 28274}, {"brawlhalla_id": 10352807, "name": "Doku", "rank": "Member", "join_date": 1658170826, "xp": 14199}, {"brawlhalla_id": 8275242, "name": "Jhonny", "rank": "Member", "join_date": 1658174887, "xp": 20923}, {"brawlhalla_id": 5503396, "name": "MRB", "rank": "Member", "join_date": 1658345270, "xp": 34796}, {"brawlhalla_id": 7159263, "name": "PCS | Shadra - Baguette senpai", "rank": "Member", "join_date": 1658395590, "xp": 28628}, {"brawlhalla_id": 3013356, "name": "oszcar", "rank": "Member", "join_date": 1658856944, "xp": 53195}, {"brawlhalla_id": 2600667, "name": "SamiGigi", "rank": "Member", "join_date": 1658948471, "xp": 8596}, {"brawlhalla_id": 69630716, "name": "mommy uwu ara ara cutie~", "rank": "Member", "join_date": 1659274583, "xp": 60185}, {"brawlhalla_id": 4639959, "name": "negatived", "rank": "Member", "join_date": 1659980209, "xp": 5045}, {"brawlhalla_id": 26084391, "name": ".diline", "rank": "Member", "join_date": 1660910171, "xp": 6931}, {"brawlhalla_id": 70022787, "name": "twitch.tv/ma2st4er5", "rank": "Officer", "join_date": 1660934058, "xp": 11123}, {"brawlhalla_id": 5111230, "name": "WelFe", "rank": "Member", "join_date": 1660938600, "xp": 5518}, {"brawlhalla_id": 7364605, "name": "CrossySpeedrun", "rank": "Member", "join_date": 1660940056, "xp": 5448}, {"brawlhalla_id": 26417667, "name": "Dobleh #Lidia", "rank": "Member", "join_date": 1660940976, "xp": 5328}, {"brawlhalla_id": 9048248, "name": "Lil Liser <3", "rank": "Member", "join_date": 1660989573, "xp": 3325}, {"brawlhalla_id": 83366016, "name": "twitch.tv/WhisperBH", "rank": "Member", "join_date": 1661004909, "xp": 11242}, {"brawlhalla_id": 1209176, "name": "woop!?", "rank": "Member", "join_date": 1661021682, "xp": 6483}, {"brawlhalla_id": 3764805, "name": "Lil'Fox <3", "rank": "Member", "join_date": 1661104096, "xp": 6387}, {"brawlhalla_id": 3794093, "name": "MrEmpanadilla19", "rank": "Member", "join_date": 1661640242, "xp": 7494}, {"brawlhalla_id": 3995547, "name": "iiTzHairu!?", "rank": "Member", "join_date": 1661858269, "xp": 624}, {"brawlhalla_id": 3221385, "name": "the neutral duck (Eldad)", "rank": "Member", "join_date": 1661870719, "xp": 627}, {"brawlhalla_id": 42572878, "name": "xFabio", "rank": "Member", "join_date": 1661871499, "xp": 1608}]}
Loading

0 comments on commit 9c97fdc

Please sign in to comment.