[BACK]Return to peebot.py CVS log [TXT][DIR] Up to [contributed] / MumbleDicebot

File: [contributed] / MumbleDicebot / peebot.py (download)

Revision 1.1, Sat Apr 24 09:22:17 2021 UTC (8 months, 3 weeks ago) by rubenllorente
Branch point for: MAIN

Initial revision

from twisted.python.rebuild import rebuild
import mumble_client as mc
import mumble_protocol as mp
import peebot
import re
import dice

OWNER = "ruben"  # Your mumble nickname
SERVER_IP = ""  # Server IP
SERVER_PORT = 64738  # Server PORT
USERNAME = "screwgoogle"  # Bot's name

# Use empty string for optional fields to remove
PASSWORD = "no subestimes el poder de Iota"  # Optional password
CERTIFICATE = ""  # Optional certificate

class PeeBotClient(mp.MumbleClient):
    def connectionMade(self):

        self.users = {}
        self.channels = {}
        self.session = 0
        self.channel = 0
        self.shutup = []
        self.follow = 0
        self.c_order = []

    def reload(self):

    def reply(self, p, msg):
        if p.channel_id:
            self.send_textmessage(msg, channels=p.channel_id)
            self.send_textmessage(msg, users=[p.actor])

    def handle_udptunnel(self, p):
        if self.users[p.session] in self.shutup:
            self.move_user(self.shutup_channel, p.session)

    def handle_channelstate(self, p):
        if p.name:
            self.channels[p.channel_id] = p.name

    def handle_userremove(self, p):
        # Remove user from userlist
        del self.users[p.session]

    def handle_userstate(self, p):
        # Add user id to the userlist
        if p.name:
            self.users[p.session] = p.name

        # Stores own session id
        if p.name == self.factory.nickname:
            self.session = p.session

        if p.session == self.session:
            self.channel = p.channel_id

        # Follows user around
        if self.users[p.session] == self.follow:
            if p.channel_id:
                self.move_user(p.channel_id, self.session)
            elif p.self_mute:
                self.mute_or_deaf(self.session, True, True)
                self.mute_or_deaf(self.session, False, False)

    def handle_textmessage(self, p):

        # Reload the script
        if p.message == "/reload":
            print "Reloaded!"

        if re.match('^/roll (.+)$', p.message):
                self.reply(p, str(dice.roll(re.search('^/roll (.+)$', p.message).group(1)+"+0")))
            except dice.DiceBaseException as e:

        # Only listen to the owner
        if self.users[p.actor] != OWNER:

        if p.message.startswith("/change"):
            channel = p.message.split(' ')[-1]
            self.move_user(int(channel), self.session)

        # List the channels in the console
        elif p.message.startswith("/channels"):
            print self.channels

        # List the users in the console
        elif p.message.startswith("/users"):
            print self.users

if __name__ == '__main__':
    factory = mc.create_client(peebot.PeeBotClient, USERNAME, PASSWORD)
    mc.start_client(factory, SERVER_IP, SERVER_PORT, certificate=CERTIFICATE)