diff --git a/make-db.py b/make-db.py index d3dd9ed..907dade 100644 --- a/make-db.py +++ b/make-db.py @@ -19,10 +19,10 @@ with open(a.input, newline='') as file: for row in reader: if len(row) == 0: continue - if len(row) <= 2: + if len(row) <= 3: entries.append(list(map(lambda x: x.strip(), row))) else: - print('encountered a row with more than two cells') + print('encountered a row with more than three cells') exit(1) if a.shuffle: @@ -36,6 +36,7 @@ cur.execute(''' CREATE TABLE entries( name TEXT UNIQUE NOT NULL, emoji TEXT, + description TEXT, status INT NOT NULL, last_poll_number INT NOT NULL, sort_number INT UNIQUE NOT NULL @@ -68,6 +69,11 @@ cur.execute(''' for i, row in enumerate(entries): name = row[0] emoji = row[1] if len(row) > 1 else None - cur.execute('INSERT INTO entries VALUES(?, ?, 0, 0, ?)', (name, emoji, i)) + description = row[2] if len(row) > 2 else None + if emoji == '': + emoji = None + if description == '': + description = None + cur.execute('INSERT INTO entries VALUES(?, ?, ?, 0, 0, ?)', (name, emoji, description, i)) dbcon.commit() diff --git a/post-poll.py b/post-poll.py index ad40fd4..fb4f8f6 100644 --- a/post-poll.py +++ b/post-poll.py @@ -32,7 +32,7 @@ last_number = cur.execute(''' poll_number = last_number[0] + 1 if last_number else 1 rows = cur.execute(''' - SELECT name, emoji FROM entries + SELECT name, emoji, description FROM entries WHERE status == 0 ORDER BY last_poll_number, sort_number LIMIT 2 @@ -48,7 +48,10 @@ def media(name, emoji): emoji_obj = {'id': emoji} if emoji.isascii() and emoji.isdigit() else {'name': emoji} return {'text': name, 'emoji': emoji_obj} -result = discord.post(discord.session(token), f'/channels/{a.channel}/messages', { +s = discord.session(token) +e = f'/channels/{a.channel}/messages' + +result = discord.post(s, e, { 'poll': { 'question': {'text': f'Poll #{poll_number}'}, 'answers': [{ @@ -60,6 +63,12 @@ result = discord.post(discord.session(token), f'/channels/{a.channel}/messages', } }) +if rows[0][2] is not None: + discord.post(s, e, {'content': rows[0][2]}) + +if rows[1][2] is not None: + discord.post(s, e, {'content': rows[1][2]}) + posted = int(time.time()) expires = posted + hours * 3600 channel_id = result['channel_id'] diff --git a/readme.txt b/readme.txt index 7843cc1..788ec2d 100644 --- a/readme.txt +++ b/readme.txt @@ -16,12 +16,12 @@ == create database == next, we need to make a csv file with a list of entries in our bracket. - each line of the csv file corresponds to one entry. if a line has one - column, the text in that column is the name of the entry. if a line has - two columns, the text in the first column is the name of the entry, and - the text in the second column is an associated emoji. this can be a unicode - emoji (at time of writing, discord supports up to unicode 15.0), or it can - be the id of a server emoji that your bot will have access to. + each line of the csv file corresponds to one entry. the first column has + the name of the entry. the second column has an associated emoji. this can + be a unicode emoji (at the time of writing, discord supports up to unicode + 15.0), or it can be the id of a server emoji that your bot will have access + to. the third column is a description for the entry, which is allowed to + use discord's markdown-like formatting. now, use the make-db.py script to create the database. there are two positional arguments, first the path where the database will be created, @@ -54,7 +54,10 @@ the most recent polls they were each in in occurred. for two entries that have the same most recent poll (i.e. ones where the most recent poll was a tie), the order from the database creation step is used. if there are not - two qualified entries, the script just prints a message and quits. + two qualified entries, the script just prints a message and quits. the two + descriptions are posted after the poll. if neither entry has a description, + no description is posted. if only one entry has a description, only the one + description is posted. == processing polls == @@ -90,6 +93,7 @@ name TEXT UNIQUE NOT NULL - json string representing the name of the entry emoji TEXT - either null, a unicode emoji, or a discord emoji id + description TEXT - either null or a description to post with any polls that have this entry status INT NOT NULL - 0 = safe, 1 = in poll, 2 = eliminated last_poll_number INT NOT NULL - poll_number for the last (or current) poll it was in, or 0 if none sort_number INT UNIQUE NOT NULL - a number used to sort the entries (the values don't matter, just the order)