Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import logging
- import random
- import markovify
- import time as t
- import plugin
- logger = logging.getLogger(__name__)
- class humanizm(plugin.Plugin):
- """Plugin that works similarly to the joke plugin, but it handles humanizm
- instead. Theoretically this could be abstracted and combined with jokes,
- but in the future we will probably want it to be handled differently, so it
- should stay as a separate module.
- """
- def __init__(self, bot):
- super(humanizm, self).__init__(bot)
- self.use_command = "!humanizm"
- self.add_command = "!addhumanizm"
- self.init_db()
- @property
- def description(self):
- return "Shows humanizm added by users."
- @property
- def long_desc(self):
- return ""
- @property
- def commands(self):
- return {
- "!humanizm": "shows random humanizm",
- "!addhumanizm": "adds a new piece of humanizm to the database"
- }
- def private_chat_hook(self, steamid, message):
- if message.startswith(self.use_command):
- self.bot.user.send_msg(steamid, self.get_humanizm())
- elif message.startswith(self.add_command):
- self.bot.user.send_msg(steamid, self.add_humanizm(steamid, message))
- def group_chat_hook(self, groupid, userid, message):
- if message.startswith(self.use_command):
- self.bot.user.send_group_msg(groupid, self.get_humanizm())
- elif message.startswith(self.add_command):
- self.bot.user.send_group_msg(groupid, self.add_humanizm(userid, message))
- def get_humanizm(self):
- rows = self.bot.database.select("humanizm", "*")
- if len(rows)<1:
- return "No humanizm in the database."
- else:
- col = rows[:,1]
- row = col.reshape(1, -1)
- return ("{}".format(row.encode('utf-8')
- ))
- def add_humanizm(self, steamid, message):
- tokens = message.split()
- if len(tokens)<2:
- return "No content. humanizm not added."
- else:
- self.bot.database.insert("humanizm", "content, author", "?, ?",
- (
- ' '.join(tokens[1:]),
- self.bot.user.get_name_from_steamid(steamid)
- )
- )
- return "humanizm added."
- def init_db(self):
- tables = self.bot.database.select("sqlite_master", "name",
- "type='table'")
- for table in tables:
- if table[0] == "humanizm":
- return
- logger.info("Creating humanizm table in the database")
- self.bot.database.create_table("humanizm",
- "id INTEGER PRIMARY KEY AUTOINCREMENT,"
- "content TEXT NOT NULL,"
- "author TEXT NOT NULL"
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement