Browse Source

Add some more killing features

pull/4/head
Schneider 6 years ago
parent
commit
2fc3d183c8
  1. 1
      .gitignore
  2. 34
      db.py
  3. 42
      schneiderbot.py

1
.gitignore

@ -1,4 +1,5 @@
token
deaths.db
# ---> Python
# Byte-compiled / optimized / DLL files

34
db.py

@ -0,0 +1,34 @@
"""DB interface"""
import sqlite3
class Db():
""" Abstract interface for db actions """
def __init__(self):
self.conn = sqlite3.connect("deaths.db")
table_exist = self.conn.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='death'")
if table_exist.fetchall() == []:
self.conn.execute("CREATE TABLE death(name)")
def __del__(self):
self.conn.commit()
def is_dead(self, user):
"""Reports whether a user is already dead"""
print(str(user))
res = self.conn.execute("select * from death where name = ?", [user])
return res.fetchall() != []
def kill(self, user):
"""Kills a user"""
self.conn.execute("insert into death(name) values(?)", [user])
def revive(self, user):
"""Revives a user"""
self.conn.execute("delete from death where name = ?", [user])
def get_dead_bodies(self):
"""List the dead"""
names = []
for name in self.conn.execute("select * from death").fetchall():
names.append(name[0])
return ", ".join(names)

42
schneiderbot.py

@ -3,6 +3,7 @@
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from telegram import ParseMode
from db import Db
import logging
import os
import random
@ -85,7 +86,7 @@ with open("stoll.txt", "r") as tmp_file:
with open("manta.txt", "r") as tmp_file:
MANTA = tmp_file.readlines()
with open("goodlife.txt", "r") as tmp_file:
GOOD_LIFE = tmp_file.readlines()
@ -128,22 +129,43 @@ def sendDog(bot, update):
def kill(bot, update, sudocall = False):
"""kill me pls"""
db = Db()
user = update.message.from_user.first_name
if db.is_dead(user):
if sudocall:
update.message.reply_text("%s killed again" % user)
return
update.message.reply_text("%s is already dead" % user)
return
message = update.message.from_user.first_name + " died"
if sudocall:
message += " for real"
db.kill(user)
update.message.reply_text(message)
def revive(bot, update, sudocall = False):
"""unkill me pls"""
message = update.message.from_user.first_name + " is living again"
db = Db()
user = update.message.from_user.first_name
if not db.is_dead(user):
update.message.reply_text("Maybe %s should have a litte 'accident' before" % user)
return
if sudocall:
message += " for real"
update.message.reply_text(message)
update.message.reply_text("%s is living again, for real" % user)
db.revive(user)
return
update.message.reply_text("You fool! You cannot revive a dead person!")
SUDOCMDS = {
"kill" : kill,
"revive" : revive
}
"kill" : kill,
"revive" : revive
}
def graveyard(bot, update):
"""List the dead"""
db = Db()
update.message.reply_text("Here are the dead people:\n%s" % db.get_dead_bodies())
def sudo(bot, update, args):
"""for real"""
@ -170,12 +192,12 @@ def manta(bot, update):
"""Boah ey, geile Karre!"""
rand = random.SystemRandom()
update.message.reply_text(MANTA[rand.randrange(0, len(MANTA), 1)])
def goodlife(bot, update):
"""GOOD LIFE MY A..."""
rand = random.SystemRandom()
update.message.reply_text(GOOD_LIFE[rand.randrange(0, len(GOOD_LIFE), 1)])
def shrug(bot, update):
"""SHRUG"""
update.message.reply_text("¯\_(ツ)_/¯")
@ -267,6 +289,7 @@ def main():
dp.add_handler(CommandHandler("kill", kill))
dp.add_handler(CommandHandler("revive", revive))
dp.add_handler(CommandHandler("simon", simon))
dp.add_handler(CommandHandler("graveyard", graveyard))
# log all errors
@ -283,4 +306,3 @@ def main():
if __name__ == '__main__':
main()
Loading…
Cancel
Save