Skip to content

Commit

Permalink
Merge pull request #45 from Skyward-Brawlhalla/refactor-some-more
Browse files Browse the repository at this point in the history
Refactor main.py #10
  • Loading branch information
CrossyChainsaw authored Sep 1, 2022
2 parents 9c97fdc + 063abff commit d97b681
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 108 deletions.
Binary file modified __pycache__/command_link_add.cpython-38.pyc
Binary file not shown.
Binary file modified __pycache__/command_link_remove.cpython-38.pyc
Binary file not shown.
7 changes: 6 additions & 1 deletion command_link_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,9 @@ async def add_link(bot, ctx, brawlhalla_id, discord_id, embed_color):
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 + '`')
+ discord_id + '`\n`brawlhalla_id: ' + brawlhalla_id + '`')

def check(author):
def inner_check(message):
return message.author == author and message.content == "Hello"
return inner_check
2 changes: 1 addition & 1 deletion command_link_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
embed_color = 0x790eab


async def delete_link_from_data(brawlhalla_id, bot, ctx):
async def remove_link(brawlhalla_id, bot, ctx):
with open('./data_link_'+ctx.guild.name+'.json') as f:
link_data = json.load(f)
num = 0
Expand Down
2 changes: 1 addition & 1 deletion data_link_Skyward.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"brawlhalla_id": "7940781", "brawlhalla_name": "Solarson", "discord_id": "228585353425059841", "discord_name": "Solarson"}, {"brawlhalla_id": "49936771", "brawlhalla_name": "Hunter", "discord_id": "541893326874345483", "discord_name": "hunterX"}, {"brawlhalla_id": "9316238", "brawlhalla_name": "Despair", "discord_id": "442041573383995415", "discord_name": "Doram!?"}, {"brawlhalla_id": "6202261", "brawlhalla_name": "Linox", "discord_id": "323167164142190593", "discord_name": "Linox"}, {"brawlhalla_id": "35913608", "brawlhalla_name": "rufus", "discord_id": "509030415496118293", "discord_name": "rufus"}, {"brawlhalla_id": "5111230", "brawlhalla_name": "WelFe", "discord_id": "249219377688215552", "discord_name": "WelFe"}, {"brawlhalla_id": "54509175", "brawlhalla_name": "RicoDelPablo!?", "discord_id": "345655312126312448", "discord_name": "RicoDelPablo"}, {"brawlhalla_id": "55666789", "brawlhalla_name": "arigato?", "discord_id": "950741489783287889", "discord_name": "arigato?"}, {"brawlhalla_id": "71428893", "brawlhalla_name": "zDisigma", "discord_id": "661163149067550731", "discord_name": "zDisigma"}, {"brawlhalla_id": "54489626", "brawlhalla_name": "Yami_ThomBozz", "discord_id": "818465649671274497", "discord_name": "Yami_ThomBozz"}, {"brawlhalla_id": "9317622", "brawlhalla_name": "Hitaku", "discord_id": "316650709456257044", "discord_name": "Hitaku"}, {"brawlhalla_id": "42952335", "brawlhalla_name": "Domagoj_playz", "discord_id": "553716871011106828", "discord_name": "Domagoj_playz"}, {"brawlhalla_id": "5708299", "brawlhalla_name": "55p", "discord_id": "303279482620346368", "discord_name": "henge"}, {"brawlhalla_id": "26084391", "brawlhalla_name": ".diline", "discord_id": "289386297527894016", "discord_name": "diline"}, {"brawlhalla_id": "61355963", "brawlhalla_name": "abzyo", "discord_id": "746433776929734748", "discord_name": "abzyo"}, {"brawlhalla_id": "2148597", "brawlhalla_name": "Guffe", "discord_id": "112578107961004032", "discord_name": "Guffe"}, {"brawlhalla_id": "26358569", "brawlhalla_name": "Uncle Timmy", "discord_id": "781919783863320577", "discord_name": "\u2325|Uncle Timmy \u1d3f\u1d49\u1da0\u1da6\u1d4d\u02b0"}, {"brawlhalla_id": "84499165", "brawlhalla_name": "Kaizaar", "discord_id": "885945279977766943", "discord_name": "Kaizaar"}, {"brawlhalla_id": "24642609", "brawlhalla_name": "Marwini", "discord_id": "338392704780075018", "discord_name": "Marwini"}, {"brawlhalla_id": "70022787", "brawlhalla_name": "twitch.tv/ma2st4er5", "discord_id": "711069947530444810", "discord_name": "ma2st4er5"}, {"brawlhalla_id": "9201392", "brawlhalla_name": "Lowkey", "discord_id": "497086786569371666", "discord_name": "Lowkey"}, {"brawlhalla_id": "3577224", "brawlhalla_name": "Zerk", "discord_id": "348134735110995988", "discord_name": "Zerk"}, {"brawlhalla_id": "74662063", "brawlhalla_name": "Roddd", "discord_id": "973613125381275739", "discord_name": "RoD"}, {"brawlhalla_id": "47231784", "brawlhalla_name": "Fochino", "discord_id": "777204277231616020", "discord_name": "Fochino"}, {"brawlhalla_id": "8615459", "brawlhalla_name": "Hidetsu?!", "discord_id": "286891632756785163", "discord_name": "Hidetsu"}, {"brawlhalla_id": "10202957", "brawlhalla_name": "Kolibric", "discord_id": "557666598853279744", "discord_name": "Kolibric"}, {"brawlhalla_id": "79985611", "brawlhalla_name": "klopj", "discord_id": "327058100332789760", "discord_name": "klopj"}, {"brawlhalla_id": "56177224", "brawlhalla_name": "EvilGaming69", "discord_id": "295944859032748034", "discord_name": "EvilGaming69"}, {"brawlhalla_id": "3221385", "brawlhalla_name": "Eldad", "discord_id": "265089434398097408", "discord_name": "El Eldad"}, {"brawlhalla_id": "3794093", "brawlhalla_name": "MrEmpanadilla19", "discord_id": "325386848820002836", "discord_name": "MrEmpanadilla19"}, {"brawlhalla_id": "40660695", "brawlhalla_name": "Friendlyherobrn", "discord_id": "303636140374884361", "discord_name": "Friendlyherobrn"}, {"brawlhalla_id": "2658232", "brawlhalla_name": "gonconist", "discord_id": "341887887995961346", "discord_name": "gonconist"}, {"brawlhalla_id": "43227947", "brawlhalla_name": "victimised AQUA", "discord_id": "645442530577612810", "discord_name": "AQUA"}, {"brawlhalla_id": "9048248", "brawlhalla_name": "Lil Liser <3", "discord_id": "648264475585019919", "discord_name": "Lil Liser"}, {"brawlhalla_id": "6433263", "brawlhalla_name": "Zwergennest", "discord_id": "386956936517648384", "discord_name": "Zwergennest"}, {"brawlhalla_id": "33893717", "brawlhalla_name": "Emma", "discord_id": "399163789397983234", "discord_name": "Emma"}, {"brawlhalla_id": "9865431", "brawlhalla_name": "LeKo", "discord_id": "515544655480487937", "discord_name": "LeKo"}, {"brawlhalla_id": "7124064", "brawlhalla_name": "woven", "discord_id": "129253606544113664", "discord_name": "Woven"}, {"brawlhalla_id": "7364605", "brawlhalla_name": "CrossyChainsaw", "discord_id": "413070742591373314", "discord_name": "CrossyChainsaw"}, {"brawlhalla_id": "6244176", "brawlhalla_name": "Sukaroo", "discord_id": "875447122919567370", "discord_name": "sukaroo"}, {"brawlhalla_id": "39794122", "brawlhalla_name": "Dex", "discord_id": "357148393115746304", "discord_name": "Dex"}, {"brawlhalla_id": "87710416", "brawlhalla_name": "Borgir", "discord_id": "943889152510951445", "discord_name": "Borgir"}, {"brawlhalla_id": "7491681", "brawlhalla_name": "Vein", "discord_id": "852620170282139709", "discord_name": "Vein .-."}, {"brawlhalla_id": "56793941", "brawlhalla_name": "G\u00c3\u00b8d-s\u00c3\u00b1\u00c3\u00aep\u00c3\u00aar", "discord_id": "507524066840674312", "discord_name": "Fighter22"}, {"brawlhalla_id": "1042492", "brawlhalla_name": "Nin", "discord_id": "823299784378548264", "discord_name": "NinGotYou"}, {"brawlhalla_id": "74627743", "brawlhalla_name": "Pseudo", "discord_id": "950076792469880894", "discord_name": "GrandBetting"}]
[{"brawlhalla_id": "7940781", "brawlhalla_name": "Solarson", "discord_id": "228585353425059841", "discord_name": "Solarson"}, {"brawlhalla_id": "49936771", "brawlhalla_name": "Hunter", "discord_id": "541893326874345483", "discord_name": "hunterX"}, {"brawlhalla_id": "9316238", "brawlhalla_name": "Despair", "discord_id": "442041573383995415", "discord_name": "Doram!?"}, {"brawlhalla_id": "6202261", "brawlhalla_name": "Linox", "discord_id": "323167164142190593", "discord_name": "Linox"}, {"brawlhalla_id": "35913608", "brawlhalla_name": "rufus", "discord_id": "509030415496118293", "discord_name": "rufus"}, {"brawlhalla_id": "5111230", "brawlhalla_name": "WelFe", "discord_id": "249219377688215552", "discord_name": "WelFe"}, {"brawlhalla_id": "54509175", "brawlhalla_name": "RicoDelPablo!?", "discord_id": "345655312126312448", "discord_name": "RicoDelPablo"}, {"brawlhalla_id": "55666789", "brawlhalla_name": "arigato?", "discord_id": "950741489783287889", "discord_name": "arigato?"}, {"brawlhalla_id": "71428893", "brawlhalla_name": "zDisigma", "discord_id": "661163149067550731", "discord_name": "zDisigma"}, {"brawlhalla_id": "54489626", "brawlhalla_name": "Yami_ThomBozz", "discord_id": "818465649671274497", "discord_name": "Yami_ThomBozz"}, {"brawlhalla_id": "9317622", "brawlhalla_name": "Hitaku", "discord_id": "316650709456257044", "discord_name": "Hitaku"}, {"brawlhalla_id": "42952335", "brawlhalla_name": "Domagoj_playz", "discord_id": "553716871011106828", "discord_name": "Domagoj_playz"}, {"brawlhalla_id": "5708299", "brawlhalla_name": "55p", "discord_id": "303279482620346368", "discord_name": "henge"}, {"brawlhalla_id": "26084391", "brawlhalla_name": ".diline", "discord_id": "289386297527894016", "discord_name": "diline"}, {"brawlhalla_id": "61355963", "brawlhalla_name": "abzyo", "discord_id": "746433776929734748", "discord_name": "abzyo"}, {"brawlhalla_id": "2148597", "brawlhalla_name": "Guffe", "discord_id": "112578107961004032", "discord_name": "Guffe"}, {"brawlhalla_id": "26358569", "brawlhalla_name": "Uncle Timmy", "discord_id": "781919783863320577", "discord_name": "\u2325|Uncle Timmy \u1d3f\u1d49\u1da0\u1da6\u1d4d\u02b0"}, {"brawlhalla_id": "84499165", "brawlhalla_name": "Kaizaar", "discord_id": "885945279977766943", "discord_name": "Kaizaar"}, {"brawlhalla_id": "24642609", "brawlhalla_name": "Marwini", "discord_id": "338392704780075018", "discord_name": "Marwini"}, {"brawlhalla_id": "70022787", "brawlhalla_name": "twitch.tv/ma2st4er5", "discord_id": "711069947530444810", "discord_name": "ma2st4er5"}, {"brawlhalla_id": "9201392", "brawlhalla_name": "Lowkey", "discord_id": "497086786569371666", "discord_name": "Lowkey"}, {"brawlhalla_id": "3577224", "brawlhalla_name": "Zerk", "discord_id": "348134735110995988", "discord_name": "Zerk"}, {"brawlhalla_id": "74662063", "brawlhalla_name": "Roddd", "discord_id": "973613125381275739", "discord_name": "RoD"}, {"brawlhalla_id": "47231784", "brawlhalla_name": "Fochino", "discord_id": "777204277231616020", "discord_name": "Fochino"}, {"brawlhalla_id": "8615459", "brawlhalla_name": "Hidetsu?!", "discord_id": "286891632756785163", "discord_name": "Hidetsu"}, {"brawlhalla_id": "10202957", "brawlhalla_name": "Kolibric", "discord_id": "557666598853279744", "discord_name": "Kolibric"}, {"brawlhalla_id": "79985611", "brawlhalla_name": "klopj", "discord_id": "327058100332789760", "discord_name": "klopj"}, {"brawlhalla_id": "56177224", "brawlhalla_name": "EvilGaming69", "discord_id": "295944859032748034", "discord_name": "EvilGaming69"}, {"brawlhalla_id": "3221385", "brawlhalla_name": "Eldad", "discord_id": "265089434398097408", "discord_name": "El Eldad"}, {"brawlhalla_id": "3794093", "brawlhalla_name": "MrEmpanadilla19", "discord_id": "325386848820002836", "discord_name": "MrEmpanadilla19"}, {"brawlhalla_id": "40660695", "brawlhalla_name": "Friendlyherobrn", "discord_id": "303636140374884361", "discord_name": "Friendlyherobrn"}, {"brawlhalla_id": "2658232", "brawlhalla_name": "gonconist", "discord_id": "341887887995961346", "discord_name": "gonconist"}, {"brawlhalla_id": "43227947", "brawlhalla_name": "victimised AQUA", "discord_id": "645442530577612810", "discord_name": "AQUA"}, {"brawlhalla_id": "9048248", "brawlhalla_name": "Lil Liser <3", "discord_id": "648264475585019919", "discord_name": "Lil Liser"}, {"brawlhalla_id": "6433263", "brawlhalla_name": "Zwergennest", "discord_id": "386956936517648384", "discord_name": "Zwergennest"}, {"brawlhalla_id": "33893717", "brawlhalla_name": "Emma", "discord_id": "399163789397983234", "discord_name": "Emma"}, {"brawlhalla_id": "9865431", "brawlhalla_name": "LeKo", "discord_id": "515544655480487937", "discord_name": "LeKo"}, {"brawlhalla_id": "7124064", "brawlhalla_name": "woven", "discord_id": "129253606544113664", "discord_name": "Woven"}, {"brawlhalla_id": "7364605", "brawlhalla_name": "CrossyChainsaw", "discord_id": "413070742591373314", "discord_name": "CrossyChainsaw"}, {"brawlhalla_id": "6244176", "brawlhalla_name": "Sukaroo", "discord_id": "875447122919567370", "discord_name": "sukaroo"}, {"brawlhalla_id": "39794122", "brawlhalla_name": "Dex", "discord_id": "357148393115746304", "discord_name": "Dex"}, {"brawlhalla_id": "87710416", "brawlhalla_name": "Borgir", "discord_id": "943889152510951445", "discord_name": "Borgir"}, {"brawlhalla_id": "7491681", "brawlhalla_name": "Vein", "discord_id": "852620170282139709", "discord_name": "Vein .-."}, {"brawlhalla_id": "56793941", "brawlhalla_name": "G\u00c3\u00b8d-s\u00c3\u00b1\u00c3\u00aep\u00c3\u00aar", "discord_id": "507524066840674312", "discord_name": "Fighter22"}, {"brawlhalla_id": "1042492", "brawlhalla_name": "Nin", "discord_id": "823299784378548264", "discord_name": "NinGotYou"}, {"brawlhalla_id": "74627743", "brawlhalla_name": "Pseudo", "discord_id": "950076792469880894", "discord_name": "GrandBetting"}, {"brawlhalla_id": "28054305", "brawlhalla_name": "syntq", "discord_id": "552032277803302913", "discord_name": "syntq!?"}, {"brawlhalla_id": "57803303", "brawlhalla_name": "Tayson", "discord_id": "793590874378469417", "discord_name": "Tayson"}]
120 changes: 15 additions & 105 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import random
from command_link_remove import delete_link_from_data
from command_link_remove import remove_link
from command_waitinglist_list import get_waitinglist_list
import config
import discord
Expand All @@ -14,6 +14,7 @@
from command_clan_update import update_clan_data
from command_discord_update import update_discord_data
from command_status import get_status
from command_link_add import add_link

# VARIABLES
intents = discord.Intents().all()
Expand Down Expand Up @@ -42,10 +43,10 @@ async def status(ctx):
async def show_all_discord_members(ctx):
# update clan data
await ctx.send(await update_discord_data(ctx))

# get discord list
msg_list = await get_discord_list(ctx)

# send discord list
embed1 = discord.Embed(description=msg_list[0], color=embed_color)
embed2 = discord.Embed(description=msg_list[1], color=embed_color)
Expand Down Expand Up @@ -81,13 +82,12 @@ async def show_all_clan_members(ctx):

@bot.command(name='rmli', description='Remove a discord-brawlhalla link')
@has_permissions(ban_members=True)
async def remove_link(ctx, brawlhalla_id):
embed1 = await delete_link_from_data(brawlhalla_id=brawlhalla_id,
bot=bot,
ctx=ctx)
async def rmli(ctx, brawlhalla_id):
# remove link from link list
await remove_link(brawlhalla_id, bot, ctx)


@remove_link.error
@rmli.error
async def missing_question(ctx, error):
await ctx.message.delete()
if isinstance(error, commands.MissingRequiredArgument):
Expand All @@ -98,8 +98,10 @@ async def missing_question(ctx, error):
@bot.command(name='lsli', description='Show All Links')
@has_permissions(ban_members=True)
async def list_link(ctx):
await ctx.message.delete()
# get link list
msg_list = await get_link_list(ctx)

# send link list
embed1 = discord.Embed(description=msg_list[0], color=embed_color)
embed2 = discord.Embed(description=msg_list[1], color=embed_color)
await ctx.channel.send(embed=embed1)
Expand All @@ -109,104 +111,12 @@ async def list_link(ctx):
print('less than 26 entries')


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


@bot.command(name='adli', aliases=['addli', 'ali'], description='Create a link between a discord and brawlhalla account')
async def add_link(ctx, brawlhalla_id, discord_id):

# 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 + '`')


def check(author):
def inner_check(message):
return message.author == author and message.content == "Hello"

return inner_check

async def qsadli(ctx, brawlhalla_id, discord_id):
# adds a link to link list
await add_link(bot, ctx, brawlhalla_id, discord_id, embed_color)

@add_link.error
@qsadli.error
async def missing_question(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send(
Expand Down

0 comments on commit d97b681

Please sign in to comment.