Exemple #1
0
 def __init__(self):
     self.room = None
     self.client = None
     self.privileged_users = []
     self.owners = []
     self.owner_name = ""
     self.chatbot_name = ""
     self.enabled = True
     self.running = True
     self.waiting_time = -1
     self.latest_word_id = -1
     self.current_word_to_reply_to = ""
     self.latest_words = []
     self.in_shadows_den = False
     self.translation_languages = [
         "auto", "en", "fr", "nl", "de", "he", "ru", "el", "pt", "es", "fi",
         "af", "sq", "ar", "hy", "az", "eu", "be", "bn", "bs", "bg", "ca",
         "ceb", "zh-CN", "hr", "cs", "da", "eo", "et", "tl", "gl", "ka",
         "gu", "ht", "ha", "hi", "hmn", "hu", "is", "ig", "id", "ga", "it",
         "ja", "jw", "kn", "km", "ko", "lo", "la", "lv", "lt", "mk", "ms"
         "mt", "mi", "mr", "mn", "ne", "no", "fa", "pl", "pa", "ro", "sr",
         "sk", "sl", "so", "sw", "sv", "ta", "te", "th", "tr", "uk", "ur",
         "vi", "cy", "yi", "yo", "zu"
     ]
     self.end_lang = None
     self.translation_chain_going_on = False
     self.translation_switch_going_on = False
     self.spell_manager = SpellManager()
     self.links = []
     self.link_explanations = []
     self.banned = {}
     self.site = ""
     self.msg_id_no_reply_found = -1
     self.owner_ids = []
     self.privileged_user_ids = []
     self.commands = {
         'translate': self.command_translate,
         'random': Commands.command_random,
         'randomint': Commands.command_randomint,
         'randomchoice': Commands.command_randomchoice,
         'shuffle': Commands.command_shuffle,
         'listcommands': self.command_listcommands,
         'help': self.command_help,
         'xkcdrandomnumber': Commands.command_xkcdrandomnumber,
         'xkcd': Commands.command_xkcd,
         'alive': Commands.command_alive,
         'utc': Commands.command_utc
     }
     self.shadows_den_specific_commands = {
         'time': self.command_time,
         'viewspells': self.command_viewspells,
         'link': self.command_link,
         'removelink': self.command_removelink,
         'addlinkexplanation': self.command_addlinkexplanation,
         'explainlink': self.command_explainlink,
         'removelinkexplanation': self.command_removelinkexplanation,
         'reply': self.command_reply,
         'showtime': self.command_showtime,
         'islink': self.command_islink,
         'latestword': self.command_latestword,
         'setlatestword': self.command_setlatestword,
         'continue': self.command_continue,
         'retry': self.command_retry,
         'rmword': self.command_rmword,
         'showlatest10': self.command_showlatest10
     }
     self.owner_commands = {
         'stop': self.command_stop,
         'disable': self.command_disable,
         'enable': self.command_enable,
         'award': self.command_award,
         'emptyqueue': self.command_emptyqueue,
         'ban': self.command_ban,
         'unban': self.command_unban,
         'translationchain': self.command_translationchain,
         'translationswitch': self.command_translationswitch,
         'removespell': self.command_removespell
     }
     self.privileged_commands = {'delete': self.command_delete}
Exemple #2
0
    def main(self):
        self.room = None
        self.client = None
        self.owner_id = 229438  # change this into your ID
        self.owner_name = "ProgramFOX"  # change this into your name
        self.enabled = True
        self.running = True
        self.waiting_time = -1
        self.current_word_to_reply_to = ""
        self.latest_words = []
        self.in_shadows_den = False
        self.translation_languages = [
            "auto", "en", "fr", "nl", "de", "he", "ru", "el", "pt", "es", "fi",
            "af", "sq", "ar", "hy", "az", "eu", "be", "bn", "bs", "bg", "ca",
            "ceb", "zh-CN", "hr", "cs", "da", "eo", "et", "tl", "gl", "ka",
            "gu", "ht", "ha", "hi", "hmn", "hu", "is", "ig", "id", "ga", "it",
            "ja", "jw", "kn", "km", "ko", "lo", "la", "lv", "lt", "mk", "ms"
            "mt", "mi", "mr", "mn", "ne", "no", "fa", "pl", "pa", "ro", "sr",
            "sk", "sl", "so", "sw", "sv", "ta", "te", "th", "tr", "uk", "ur",
            "vi", "cy", "yi", "yo", "zu"
        ]
        self.end_lang = None
        self.translation_chain_going_on = False
        self.translation_switch_going_on = False
        self.spell_manager = SpellManager()
        self.links = []
        self.banned = {}
        self.site = ""
        self.setup_logging()
        self.msg_id_no_reply_found = -1
        self.commands = {
            'translationchain': self.command_translationchain,
            'translationswitch': self.command_translationswitch,
            'translate': self.command_translate,
            'random': self.command_random,
            'randomint': self.command_randomint,
            'randomchoice': self.command_randomchoice,
            'shuffle': self.command_shuffle,
            'listcommands': self.command_listcommands,
            'help': self.command_help
        }
        self.shadows_den_specific_commands = {
            'time': self.command_time,
            'viewspells': self.command_viewspells,
            'link': self.command_link,
            'removelink': self.command_removelink,
            'reply': self.command_reply
        }
        self.owner_commands = {
            'stop': self.command_stop,
            'disable': self.command_disable,
            'enable': self.command_enable,
            'award': self.command_award,
            'emptyqueue': self.command_emptyqueue,
            'ban': self.command_ban,
            'unban': self.command_unban
        }
        self.spell_manager.init()
        in_den = raw_input("Does the bot run in Shadow's Den? (y/n) ").lower()
        if in_den == "y":
            self.in_shadows_den = True
        elif in_den == "n":
            self.in_shadows_den = False
        else:
            self.in_shadows_den = False
            print("Invalid input; assumed 'no'")
        self.site = raw_input("Site: ")
        room_number = int(raw_input("Room number: "))
        email = raw_input("Email address: ")
        password = getpass.getpass("Password: "******"config.txt"):
            f = open("config.txt", "r")
            self.waiting_time = int(f.read())
            f.close()
        else:
            f = open("config.txt", "w")
            f.write("20")
            f.close()

        if os.path.isfile("linkedWords.txt"):
            with open("linkedWords.txt", "r") as f:
                self.links = pickle.load(f)
        if os.path.isfile("bannedUsers.txt"):
            with open("bannedUsers.txt", "r") as f:
                self.banned = pickle.load(f)

        self.client = chatexchange.client.Client(self.site)
        self.client.login(email, password)

        self.spell_manager.c = self.client

        self.room = self.client.get_room(room_number)
        self.room.join()
        bot_message = "Bot started with waiting time set to %i seconds." % self.waiting_time if self.in_shadows_den else "Bot started."
        self.room.send_message(bot_message)
        self.room.watch(self.on_event)

        thread.start_new_thread(self.scheduled_empty_queue, ())

        while self.running:
            inputted = raw_input("<< ")
            if inputted.startswith("$") and len(inputted) > 2:
                command_in = inputted[2:]
                command_out = self.command(command_in, None, None)
                if command_out != False and command_out is not None:
                    print command_out
                if inputted[1] == "+":
                    self.room.send_message("%s" % command_out)
            else:
                self.room.send_message(inputted)