summaryrefslogtreecommitdiffstats
path: root/Reaktor/titlebot/commands/up
diff options
context:
space:
mode:
Diffstat (limited to 'Reaktor/titlebot/commands/up')
-rwxr-xr-xReaktor/titlebot/commands/up33
1 files changed, 33 insertions, 0 deletions
diff --git a/Reaktor/titlebot/commands/up b/Reaktor/titlebot/commands/up
new file mode 100755
index 00000000..0a48bdb0
--- /dev/null
+++ b/Reaktor/titlebot/commands/up
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+import json
+from os import environ
+import sys
+import os
+# krebs polling
+import poll
+
+f = 'suggestions.json'
+db = poll.load_db(f)
+votes = []
+votes = sys.argv[1:]
+if not votes:
+ print("""usage: up number (...)
+ upvotes one or more entries based on .list""")
+ sys.exit(1)
+
+voter = environ['_prefix']
+voter_name =environ['_from']
+for vote in votes:
+ try:
+ vote = int(vote)
+ if vote < 0:
+ raise Exception()
+ if voter in db[vote]['votes']:
+ print("%s, you already have voted for '%s'"%(voter_name,db[vote]['title']) )
+ else:
+ db[vote]['votes'][voter] = 1
+ print("%s voted for '%s'"%(voter_name,db[vote]['title']))
+ except:
+ print("%s, voting for #%s failed" %(voter_name,vote))
+
+poll.save_db(f,db)