add descriptions for entries
This commit is contained in:
parent
1b9499b404
commit
f5d3019a28
3 changed files with 31 additions and 12 deletions
12
make-db.py
12
make-db.py
|
@ -19,10 +19,10 @@ with open(a.input, newline='') as file:
|
||||||
for row in reader:
|
for row in reader:
|
||||||
if len(row) == 0:
|
if len(row) == 0:
|
||||||
continue
|
continue
|
||||||
if len(row) <= 2:
|
if len(row) <= 3:
|
||||||
entries.append(list(map(lambda x: x.strip(), row)))
|
entries.append(list(map(lambda x: x.strip(), row)))
|
||||||
else:
|
else:
|
||||||
print('encountered a row with more than two cells')
|
print('encountered a row with more than three cells')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if a.shuffle:
|
if a.shuffle:
|
||||||
|
@ -36,6 +36,7 @@ cur.execute('''
|
||||||
CREATE TABLE entries(
|
CREATE TABLE entries(
|
||||||
name TEXT UNIQUE NOT NULL,
|
name TEXT UNIQUE NOT NULL,
|
||||||
emoji TEXT,
|
emoji TEXT,
|
||||||
|
description TEXT,
|
||||||
status INT NOT NULL,
|
status INT NOT NULL,
|
||||||
last_poll_number INT NOT NULL,
|
last_poll_number INT NOT NULL,
|
||||||
sort_number INT UNIQUE NOT NULL
|
sort_number INT UNIQUE NOT NULL
|
||||||
|
@ -68,6 +69,11 @@ cur.execute('''
|
||||||
for i, row in enumerate(entries):
|
for i, row in enumerate(entries):
|
||||||
name = row[0]
|
name = row[0]
|
||||||
emoji = row[1] if len(row) > 1 else None
|
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()
|
dbcon.commit()
|
||||||
|
|
13
post-poll.py
13
post-poll.py
|
@ -32,7 +32,7 @@ last_number = cur.execute('''
|
||||||
poll_number = last_number[0] + 1 if last_number else 1
|
poll_number = last_number[0] + 1 if last_number else 1
|
||||||
|
|
||||||
rows = cur.execute('''
|
rows = cur.execute('''
|
||||||
SELECT name, emoji FROM entries
|
SELECT name, emoji, description FROM entries
|
||||||
WHERE status == 0
|
WHERE status == 0
|
||||||
ORDER BY last_poll_number, sort_number
|
ORDER BY last_poll_number, sort_number
|
||||||
LIMIT 2
|
LIMIT 2
|
||||||
|
@ -48,7 +48,10 @@ def media(name, emoji):
|
||||||
emoji_obj = {'id': emoji} if emoji.isascii() and emoji.isdigit() else {'name': emoji}
|
emoji_obj = {'id': emoji} if emoji.isascii() and emoji.isdigit() else {'name': emoji}
|
||||||
return {'text': name, 'emoji': emoji_obj}
|
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': {
|
'poll': {
|
||||||
'question': {'text': f'Poll #{poll_number}'},
|
'question': {'text': f'Poll #{poll_number}'},
|
||||||
'answers': [{
|
'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())
|
posted = int(time.time())
|
||||||
expires = posted + hours * 3600
|
expires = posted + hours * 3600
|
||||||
channel_id = result['channel_id']
|
channel_id = result['channel_id']
|
||||||
|
|
18
readme.txt
18
readme.txt
|
@ -16,12 +16,12 @@
|
||||||
== create database ==
|
== create database ==
|
||||||
|
|
||||||
next, we need to make a csv file with a list of entries in our bracket.
|
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
|
each line of the csv file corresponds to one entry. the first column has
|
||||||
column, the text in that column is the name of the entry. if a line has
|
the name of the entry. the second column has an associated emoji. this can
|
||||||
two columns, the text in the first column is the name of the entry, and
|
be a unicode emoji (at the time of writing, discord supports up to unicode
|
||||||
the text in the second column is an associated emoji. this can be a unicode
|
15.0), or it can be the id of a server emoji that your bot will have access
|
||||||
emoji (at time of writing, discord supports up to unicode 15.0), or it can
|
to. the third column is a description for the entry, which is allowed to
|
||||||
be the id of a server emoji that your bot will have access to.
|
use discord's markdown-like formatting.
|
||||||
|
|
||||||
now, use the make-db.py script to create the database. there are two
|
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,
|
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
|
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
|
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
|
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 ==
|
== processing polls ==
|
||||||
|
|
||||||
|
@ -90,6 +93,7 @@
|
||||||
|
|
||||||
name TEXT UNIQUE NOT NULL - json string representing the name of the entry
|
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
|
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
|
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
|
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)
|
sort_number INT UNIQUE NOT NULL - a number used to sort the entries (the values don't matter, just the order)
|
||||||
|
|
Loading…
Add table
Reference in a new issue