Skip to content

Commit 08e1b2f

Browse files
committed
minor changes, not sure if the tweeting stuff will actually work.
1 parent 2ca878a commit 08e1b2f

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

sfcjbot.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ async def on_message(message):
6464
await set_secondary(message, "region")
6565
return
6666

67+
if "set_cfn" in command.lower() or "set cfn" in command.lower() or "cfn" in command.lower():
68+
await set_secondary(message, "cfn")
69+
return
70+
6771
if "alias" in command.lower() or "games" in command.lower():
6872
await tell_aliases(message)
6973
return
@@ -101,7 +105,7 @@ async def on_message(message):
101105
return
102106

103107
async def addgame(game_to_add, message):
104-
# FIXME see Github issue about this.
108+
# FIXME see GitHub issue about this.
105109
if message.author.permissions_in(message.channel).kick_members:
106110
add_game="INSERT INTO games (game) VALUES ('"+game_to_add+"')"
107111
await db_wrapper.execute(client, message.author, add_game, True)
@@ -142,25 +146,24 @@ async def describe(message):
142146
user_description = discord_user + " is queued up for " + ", ".join(list_of_users_games) + "\n"
143147
else:
144148
user_description = discord_user + " isn't queued up for any games.\n"
145-
user_description_query = "SELECT challonge, fightcade FROM users WHERE username='" + discord_user + "'"
149+
user_description_query = "SELECT challonge, fightcade, cfn FROM users WHERE username='" + discord_user + "'"
146150
user_description_result = await db_wrapper.execute(client, message.author, user_description_query, True)
147151
if str(user_description_result) == "()":
148152
await client.send_message(message.author, "I don't know anyone named " + discord_user + ".")
149153
return
150154
user_description_tuple = user_description_result[0]
151-
if user_description_tuple[0] is not None:
155+
if user_description_tuple[0]:
152156
user_description += "Their Challonge username is " + user_description_tuple[0] + "."
153-
else:
154-
user_description += "I don't know their Challonge username."
155157
if user_description_tuple[1]:
156158
user_description += " Their Fightcade username is " + user_description_tuple[1] + "."
157-
else:
158-
user_description += " I don't know their Fightcade username."
159+
if user_description_tuple[2]:
160+
user_description += " Their CFN is " + user_description_tuple[2] + "."
159161
await client.send_message(message.author, user_description)
160162
print(str(datetime.now())+": gave " + discord_user + "'s description to " + message.author.name + ".")
161163
return
162164

163-
async def getPlayerInfoWithChallonge(message, tournament, challonge_id):
165+
166+
async def getDiscordFightcadeUsingChallonge(message, tournament, challonge_id):
164167
# We have a Challonge ID and we need a Discord user and a Fightcade username.
165168
# if we can't get that, we'll just print the Challonge username.
166169
getDiscordFightcadeQuery = "SELECT discord_id, fightcade FROM users WHERE challonge_id = '" + str(challonge_id) + "'"
@@ -278,12 +281,11 @@ async def pairing(message):
278281
# Mod version of command. Ping everybody in the tournament with their pairing.
279282
for tournament in tournaments:
280283
discord_output += "\nPairings for " + tournament["game-name"] + ": \n"
281-
match_params = {'state':"open"}
282-
# FIXME only get current matches (i.e. Round 1 or whatever.)
284+
match_params = {'state':"pending"}
283285
matches = challonge.matches.index(tournament["id"], **match_params)
284286
for match in matches:
285-
player1 = await getPlayerInfoWithChallonge(message, tournament, match["player1-id"])
286-
player2 = await getPlayerInfoWithChallonge(message, tournament, match["player2-id"])
287+
player1 = await getDiscordFightcadeUsingChallonge(message, tournament, match["player1-id"])
288+
player2 = await getDiscordFightcadeUsingChallonge(message, tournament, match["player2-id"])
287289
discord_output += player1 + " vs. " + player2 + "\n"
288290
else:
289291
# TODO Regular version of command. Only ping the person who asked.

tournament_creator.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import string
44
import twitter
55
import random
6+
import datetime
67

78
# This script needs three files and a datetime as arguments to run.
89
# The first file must be a newline-delimited list of the games which you wish to run tournaments for.
@@ -11,6 +12,7 @@
1112
# The third file should be four lines, countaining your Twitter authentication information.
1213
# datetime_tourny_start format: "2015-01-19T16:57:17-05:00"
1314
# you can get this agument with gnu's date via a command similar to 'date -d "next Friday 8 pm" +%FT%H:%M:%S%:z'
15+
# if you are using cron to run this, be sure to escape those percent signs with backslashes! +\%FT\%H:\%M:\%S\%:z
1416
this_program, games_filename, challonge_auth_filename, twitter_auth_filename, datetime_tourny_start = argv
1517

1618
# read the games file
@@ -45,13 +47,18 @@
4547
tourny_url = "".join(random.choice(string.ascii_lowercase) for _ in xrange(0, 15))
4648
tournament = {'tournament_type':"double elimination", 'show_rounds':True, 'game_name':game_to_make_a_tournament_for.rstrip(), 'open_signup':True, 'public_sign_up':True, 'start_at':datetime_tourny_start, 'check_in_duration':15}
4749
response = challonge.tournaments.create(game_to_make_a_tournament_for.rstrip(), tourny_url, **tournament)
48-
print("Challonge response:\n" + str(response))
50+
print("Challonge response:\n" + str(response) + "\n")
4951

5052
# write the file
5153
file_of_games = open(games_filename, "w")
5254
for line in games:
5355
file_of_games.write(line)
5456
file_of_games.close()
5557

56-
# TODO tweet about it
57-
58+
tournament_date = datetime.date.today()
59+
tournament_date.year = datetime_tourny_start[0:3]
60+
tournament_date.month = datetime_tourny_start[5:6]
61+
tournament_date.day = datetime_tourny_start[8:9]
62+
tweet = "This " + tournament_date.weekday + " we're having a " + game_to_make_a_tournament_for.rstrip() + " tournament! Join us: " + response["sign-up-url"]
63+
print(tweet)
64+
twitter_api.postUpdate(tweet)

0 commit comments

Comments
 (0)