-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linking #19
base: master
Are you sure you want to change the base?
Linking #19
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
298910672731766784:76561198404047726 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,14 +13,16 @@ | |
from discord.ext.commands import Bot | ||
|
||
try: | ||
from config import TOKEN, BOT_PREFIX | ||
from config_example import TOKEN, BOT_PREFIX | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be reverted. |
||
except ImportError: | ||
print('Unable to run bot, as token does not exist!') | ||
sys.exit() | ||
|
||
bot = Bot(BOT_PREFIX) | ||
bot.remove_command("help") | ||
|
||
NotLinked = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. load it into a map at bot startup and then not have a global variable |
||
|
||
|
||
def get_json(url): | ||
try: | ||
|
@@ -274,9 +276,49 @@ async def get_profile(ctx): | |
args = ctx.message.content.split(" ") | ||
|
||
if len(args) < 2: | ||
await bot.send_message(ctx.message.channel, | ||
PastUsers = open("UserIDs.txt", "r+") | ||
NotLinked = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should load this at bot startup instead of at every call |
||
for line in PastUsers: | ||
check = line | ||
check = check.strip() | ||
check = check.split(":") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing as the other comment. Possibly put this code in a function so you don't have to write it twice. |
||
##print(check) | ||
if check[0] == ctx.message.author.id: | ||
NotLinked = False | ||
break | ||
else: | ||
NotLinked = True | ||
if NotLinked: | ||
await bot.send_message(ctx.message.channel, | ||
f"Not enough arguments! The proper form of this command is: `{BOT_PREFIX}profile <id>`") | ||
return | ||
return | ||
else: | ||
# fetches the profile for the ID. if user can not be found, tell the user so. | ||
id = check[1] | ||
response_stats = get_json("https://calculated.gg/api/player/{}/profile_stats".format(id)) | ||
|
||
car_name = response_stats["car"]["carName"] | ||
car_percentage = str(round(response_stats["car"]["carPercentage"] * 100, 1)) + "%" | ||
avatar_link, avatar_name, platform, past_names = get_player_profile(id) | ||
|
||
list_past_names = "" | ||
for name in past_names: | ||
list_past_names = list_past_names + name + "\n" | ||
|
||
# creates stats_embed | ||
stats_embed = discord.Embed( | ||
color=discord.Color.blue() | ||
) | ||
|
||
stats_embed.set_author(name=avatar_name, url="https://calculated.gg/players/{}/overview".format(id), | ||
icon_url="https://media.discordapp.net/attachments/495315775423381518/499488781536067595/bar_graph-512.png") | ||
stats_embed.set_thumbnail(url=avatar_link) | ||
stats_embed.add_field(name="Favourite car", value=car_name + " (" + car_percentage + ")") | ||
stats_embed.add_field(name="Past names", value=list_past_names) | ||
|
||
# send message | ||
await bot.send_message(ctx.message.channel, embed=stats_embed) | ||
return | ||
elif len(args) > 2: | ||
await bot.send_message(ctx.message.channel, | ||
f"Too many arguments! The proper form of this command is: `{BOT_PREFIX}profile <id>`") | ||
|
@@ -320,8 +362,45 @@ async def get_rank(ctx): | |
args = ctx.message.content.split(" ") | ||
|
||
if len(args) < 2: | ||
await bot.send_message(ctx.message.channel, | ||
f"Not enough arguments! The proper form of this command is: `{BOT_PREFIX}ranks <id>`") | ||
PastUsers = open("UserIDs.txt", "r+") | ||
NotLinked = True | ||
for line in PastUsers: | ||
check = line | ||
check = check.strip() | ||
check = check.split(":") | ||
ThatGuyDed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
##print(check) | ||
if check[0] == ctx.message.author.id: | ||
NotLinked = False | ||
break | ||
else: | ||
NotLinked = True | ||
if NotLinked: | ||
await bot.send_message(ctx.message.channel, | ||
f"Not enough arguments! The proper form of this command is: `{BOT_PREFIX}profile <id>`") | ||
return | ||
else: | ||
# fetches the profile for the ID. if user can not be found, tell the user so. | ||
id = check[1] | ||
avatar_link, avatar_name, platform, past_names = get_player_profile(id) | ||
|
||
# get user's ranks | ||
ranks = get_json("https://calculated.gg/api/player/{}/ranks".format(id)) | ||
|
||
# create embed | ||
stats_embed = discord.Embed( | ||
color=discord.Color.blue() | ||
) | ||
|
||
stats_embed.set_author(name=avatar_name, url="https://calculated.gg/players/{}/overview".format(id), | ||
icon_url="https://media.discordapp.net/attachments/495315775423381518/499488781536067595/bar_graph-512.png") | ||
stats_embed.set_thumbnail(url=avatar_link) | ||
order = ['duel', 'doubles', 'solo', 'standard', 'hoops', 'rumble', 'dropshot', 'snowday'] | ||
for playlist in order: | ||
stats_embed.add_field(name=playlist.title(), value=ranks[playlist]['name'] + " - " + str(ranks[playlist]['rating'])) | ||
|
||
# send embed | ||
await bot.send_message(ctx.message.channel, embed=stats_embed) | ||
|
||
return | ||
elif len(args) > 2: | ||
await bot.send_message(ctx.message.channel, | ||
|
@@ -641,6 +720,49 @@ async def status_replay(ctx): | |
await bot.send_message(ctx.message.channel, message) | ||
return | ||
|
||
#Command for linking accounts so that commands are quicker to run (And to stop me from looking stupid when I forget to put my account on the end of commands) | ||
@bot.command(name="link", aliases=["l"], pass_context=True) | ||
async def test(ctx): | ||
#Gets id that is being linked to | ||
args = ctx.message.content.split(" ") | ||
UserID = args[1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Snake case for all variables please. |
||
UserID = resolve_custom_url(args[1]) | ||
#Opens text document with linked names | ||
PastUsers = open("UserIDs.txt", "r+") | ||
NotLinked = True | ||
#Gets names from text document | ||
for line in PastUsers: | ||
check = line | ||
check = check.strip() | ||
check = check.split(":") | ||
##print(check) | ||
#Checks to see if an account is already linked to discord account | ||
if check[0] == ctx.message.author.id: | ||
await bot.send_message(ctx.message.channel, "Your account is already linked!") | ||
NotLinked = False | ||
break | ||
else: | ||
NotLinked = True | ||
if NotLinked: | ||
#If the user isn't linked, tries to link with the account name / id given | ||
try: | ||
sender = ctx.message.author.id | ||
save_info = sender + ":" + UserID + "\n" | ||
##print(save_info) | ||
#Saves linked account info to text document then closes it and tells them it is linked | ||
if UserID == "User not found": | ||
await bot.send_message(ctx.message.channel, "User could not be found, please try again.") | ||
return | ||
else: | ||
PastUsers.write(save_info) | ||
PastUsers.close() | ||
await bot.send_message(ctx.message.channel, "Account Successfully linked!") | ||
|
||
except: | ||
await bot.send_message(ctx.message.channel, "User could not be found, please try again.") | ||
return | ||
##print("Working") | ||
|
||
|
||
# when bot user is ready, prints "READY", and set presence | ||
@bot.event | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
TOKEN = "" | ||
BOT_PREFIX = "!" | ||
BOT_PREFIX = "!" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not need to be committed.
But I like the format of it