Exemplo n.º 1
0
def test_display():
    """Test display functions."""
    check(weechat.prefix('action') != '')
    check(weechat.prefix('error') != '')
    check(weechat.prefix('join') != '')
    check(weechat.prefix('network') != '')
    check(weechat.prefix('quit') != '')
    check(weechat.prefix('unknown') == '')
    check(weechat.color('green') != '')
    check(weechat.color('unknown') == '')
    weechat.prnt('', '## test print core buffer')
    weechat.prnt_date_tags('', 946681200, 'tag1,tag2',
                           '## test print_date_tags core buffer')
    buffer = weechat.buffer_new('test_formatted', 'buffer_input_cb', '',
                                'buffer_close_cb', '')
    check(buffer != '')
    check(weechat.buffer_get_integer(buffer, 'type') == 0)
    weechat.prnt(buffer, '## test print formatted buffer')
    weechat.prnt_date_tags(buffer, 946681200, 'tag1,tag2',
                           '## test print_date_tags formatted buffer')
    weechat.buffer_close(buffer)
    buffer = weechat.buffer_new_props('test_free', {'type': 'free'},
                                      'buffer_input_cb', '', 'buffer_close_cb',
                                      '')
    check(weechat.buffer_get_integer(buffer, 'type') == 1)
    check(buffer != '')
    weechat.prnt_y(buffer, 0, '## test print_y free buffer')
    weechat.prnt_y_date_tags(buffer, 0, 946681200, 'tag1,tag2',
                             '## test print_y_date_tags free buffer')
    weechat.buffer_close(buffer)
Exemplo n.º 2
0
def floodit_input_buffer(data, buffer, input):
    """Input data in floodit buffer."""
    global floodit
    if input:
        args = input.split(' ')
        if args[0] in ('d', 'demo'):
            if not floodit['timer']:
                delay = 500
                if len(args) > 1:
                    try:
                        delay = int(args[1])
                    except:
                        delay = 500
                if delay <= 0:
                    delay = 1
                if floodit['end']:
                    floodit_new_game()
                floodit['timer'] = weechat.hook_timer(delay, 0, 0, 'floodit_timer_cb', '')
        elif args[0] in ('s', 'single'):
            floodit['mode'] = 'single'
            floodit_new_game()
        elif args[0] in ('v', 'versus'):
            floodit['mode'] = 'versus'
            floodit_new_game()
        elif args[0] in ('n', 'new'):
            floodit_new_game()
        elif args[0] in ('q', 'quit'):
            weechat.buffer_close(floodit['buffer'])
        elif args[0] == '+':
            floodit_change_size(+1)
        elif args[0] == '-':
            floodit_change_size(-1)
    return weechat.WEECHAT_RC_OK
Exemplo n.º 3
0
def vdm_buffer_input(data, buffer, input_data):
    """ Read data from user in VDM buffer. """
    if input_data == "q" or input_data == "Q":
        weechat.buffer_close(buffer)
    else:
        vdm_get(input_data)
    return weechat.WEECHAT_RC_OK
Exemplo n.º 4
0
def floodit_input_buffer(data, buffer, input):
    """Input data in floodit buffer."""
    global floodit
    if input:
        args = input.split(' ')
        if args[0] in ('d', 'demo'):
            if not floodit['timer']:
                delay = 500
                if len(args) > 1:
                    try:
                        delay = int(args[1])
                    except:
                        delay = 500
                if delay <= 0:
                    delay = 1
                if floodit['end']:
                    floodit_new_game()
                floodit['timer'] = weechat.hook_timer(delay, 0, 0,
                                                      'floodit_timer_cb', '')
        elif args[0] in ('s', 'single'):
            floodit['mode'] = 'single'
            floodit_new_game()
        elif args[0] in ('v', 'versus'):
            floodit['mode'] = 'versus'
            floodit_new_game()
        elif args[0] in ('n', 'new'):
            floodit_new_game()
        elif args[0] in ('q', 'quit'):
            weechat.buffer_close(floodit['buffer'])
        elif args[0] == '+':
            floodit_change_size(+1)
        elif args[0] == '-':
            floodit_change_size(-1)
    return weechat.WEECHAT_RC_OK
Exemplo n.º 5
0
def vdm_buffer_input(data, buffer, input_data):
    """ Read data from user in VDM buffer. """
    if input_data == "q" or input_data == "Q":
        weechat.buffer_close(buffer)
    else:
        vdm_get(input_data)
    return weechat.WEECHAT_RC_OK
Exemplo n.º 6
0
def tictactoe_input_buffer(data, buf, input_data):
    """Input data in tictactoe buffer."""
    # pylint: disable=unused-argument
    if input_data:
        args = input_data.split(' ')
        if args[0] in ('n', 'new'):
            tictactoe_new_game()
        elif args[0] in ('c', 'computer'):
            tictactoe_new_game(computer_begins=True)
        elif args[0] in ('q', 'quit'):
            weechat.buffer_close(tictactoe['buffer'])
        elif args[0].isdigit() and not tictactoe['end']:
            pos = int(args[0])
            if 1 <= pos <= 9:
                posconv = {
                    1: 6,
                    2: 7,
                    3: 8,
                    4: 3,
                    5: 4,
                    6: 5,
                    7: 0,
                    8: 1,
                    9: 2,
                }
                tictactoe_play(tictactoe['human'], posconv[pos])
    return weechat.WEECHAT_RC_OK
Exemplo n.º 7
0
def close_buffers_by_names(names):
    for name in names:
        buf = weechat.buffer_search('python', name)
        if buf:
            weechat.prnt('', 'Closing buffer %s' % name)
            weechat.buffer_close(buf)
        else:
            weechat.prnt('', 'Error searching buffer %s' % name)
Exemplo n.º 8
0
def maze_input_buffer(data: str, buffer: str, str_input: str) -> int:
    """Input data in maze buffer."""
    # pylint: disable=unused-argument
    if str_input.lower() == "q":
        weechat.buffer_close(buffer)
    else:
        weechat.command("", f"/{SCRIPT_COMMAND} {str_input}")
    return weechat.WEECHAT_RC_OK
Exemplo n.º 9
0
def handle_query(data, signal, signal_data):
    global buffer_data
    # data: empty string
    # signal: <server>,irc_in_PRIVMSG
    # signal_data: whole message unparsed
    # parse the message
    parsed = weechat.info_get_hashtable("irc_message_parse",
                                        {"message": signal_data})
    # where should we answer?
    server = signal.split(",")[0]
    channel = parsed["channel"]
    current_nick = weechat.info_get("irc_nick", server)
    user = parsed["nick"]
    message = parsed["text"]

    if channel == current_nick:
        # we got a message through a private query, refuse it
        buffer_out = weechat.info_get("irc_buffer", server + "," + user)
        # close private buffers, but not server buffers
        # localvar_type can assume five values: private, channel, server, weechat and ""
        if weechat.buffer_get_string(buffer_out,"localvar_type") == "private":
            weechat.command(buffer_out, "How about speaking to me in public?")
            weechat.buffer_close(buffer_out)
    else:
        # query came from public channel
        if message.startswith(current_nick + ":"): # it's a command to our bot
            query = message.split(":")[1].strip() # remove the part before the colon, and lead/trail whitespaces
            s = query.split(" ", 1)
            command = s[0].lower() # command is case-insensitive
            args = s[1] if len(s) == 2 else ""
            target = "{0},{1}".format(server, channel) # this is the key to the dict containing the lists
            if command == "coin":
                out_msg = _coin()
            elif command == "help":
                out_msg = _help(user)
            elif command == "dice":
                out_msg = _dice(args)
            elif command == "server":
                out_msg = _server()
            elif command == "about":
                out_msg = _about()
            elif command == "rps":
                out_msg = _rps(user, args)
            elif command == "list":
                out_msg = _list(target,user,args)
            elif command == "coffee":
                out_msg = _coffee()
            elif command == "eightball":
                out_msg = _8ball()
            else:
                out_msg = "Unrecognized command. Type '{0}: help' to get a list of commands".format(current_nick)

            buffer_out = weechat.info_get("irc_buffer", server + "," + channel)
            if weechat.buffer_get_string(buffer_out,"localvar_type") == "channel":
                weechat.command(buffer_out, out_msg)

    return weechat.WEECHAT_RC_OK # must always return this or WEECHAT_RC_ERROR
Exemplo n.º 10
0
 def delete(self) :
     for chat in reversed(self.chats) :
         chat.delete()
     self.disconnect()
     if self.buffer is not None :
         weechat.buffer_close(self.buffer)
         self.buffer = None
     for option in self.options.keys():
         weechat.config_option_free(option)
Exemplo n.º 11
0
 def delete(self):
     for chat in reversed(self.chats):
         chat.delete()
     self.disconnect()
     if self.buffer is not None:
         weechat.buffer_close(self.buffer)
         self.buffer = None
     for option in self.options:
         weechat.config_option_free(option)
Exemplo n.º 12
0
 def create(self):
     buffer = weechat.buffer_search('python', self.__name__)
     if buffer:
         # close it because the callbacks migth be no longer valid
         weechat.buffer_close(buffer)
     buffer = self._create()
     if self._title:
         weechat.buffer_set(buffer, 'title', self._title)
     self._pointer = buffer
     return buffer
Exemplo n.º 13
0
def shell_input_buffer(data, buffer, input):
    """Input callback on shell buffer."""
    global cmd_send_to_buffer
    if input in ('q', 'Q'):
        weechat.buffer_close(buffer)
        return weechat.WEECHAT_RC_OK
    cmd_send_to_buffer = 'new'
    weechat.prnt(buffer, '')
    command = weechat.string_input_for_buffer(input)
    shell_exec(buffer, command)
    return weechat.WEECHAT_RC_OK
Exemplo n.º 14
0
def timelined_cb(data, command, rc, stdout, stderr):
    """Very generic callback in case timelined acts weird."""
    global buffers
    buf = buffers[data]
    name = wc.buffer_get_string(buf, "name")
    stream = data + "STREAM"
    del(hooks[stream])
    wc.buffer_close(buf)
    print_error("timelined for %s exited:" % name)
    print_error(stdout)
    print_error(stderr)
    return wc.WEECHAT_RC_OK
Exemplo n.º 15
0
def timelined_cb(data, command, rc, stdout, stderr):
    """Very generic callback in case timelined acts weird."""
    global buffers
    buf = buffers[data]
    name = wc.buffer_get_string(buf, "name")
    stream = data + "STREAM"
    del (hooks[stream])
    wc.buffer_close(buf)
    print_error("timelined for %s exited:" % name)
    print_error(stdout)
    print_error(stderr)
    return wc.WEECHAT_RC_OK
Exemplo n.º 16
0
def minesweeper_input_buffer(data, buffer, input):
    """Input data in minesweeper buffer."""
    global minesweeper
    if input:
        args = input.split(' ')
        if args[0] in ('n', 'new'):
            minesweeper_new_game()
        elif args[0] in ('q', 'quit'):
            weechat.buffer_close(minesweeper['buffer'])
        elif args[0] == '+':
            minesweeper_change_size(+1)
        elif args[0] == '-':
            minesweeper_change_size(-1)
    return weechat.WEECHAT_RC_OK
Exemplo n.º 17
0
def minesweeper_input_buffer(data, buffer, input):
    """Input data in minesweeper buffer."""
    global minesweeper
    if input:
        args = input.split(' ')
        if args[0] in ('n', 'new'):
            minesweeper_new_game()
        elif args[0] in ('q', 'quit'):
            weechat.buffer_close(minesweeper['buffer'])
        elif args[0] == '+':
            minesweeper_change_size(+1)
        elif args[0] == '-':
            minesweeper_change_size(-1)
    return weechat.WEECHAT_RC_OK
Exemplo n.º 18
0
def recv_cb(data, remaining_calls):
    for server in xd:
        try:
            message_data = xd[server]["socket"].recv()
            j = json.loads(message_data)

            if j["evt"] == "message/new":
                # get buffer that corresponds to the channel ID
                buffer_ = weechat.buffer_search(
                    "python", xd[server]["channels"][j["data"]["message"]
                                                     ["channelID"]]["name"])

                # display the message!
                display_msg(buffer_, j["data"]["message"], xd[server],
                            "notify_message")

            elif j["evt"] == "pingdata":
                pong_data = json.dumps({
                    "evt": "pongdata",
                    "data": {
                        "sessionID": xd[server]["session_id"]
                    }
                })
                xd[server]["socket"].send(pong_data)
        except websocket.WebSocketConnectionClosedException:
            weechat.prnt(
                "", "weecent\tLost connection to server %s. Reconnecting..." %
                server)

            # close socket
            xd[server]["socket"].close()
            del xd[server]["socket"]

            # delete everything because I'm lazy
            weechat.buffer_close(xd[server]["buffer"])
            for channel in xd[server]["channels"].itervalues():
                weechat.buffer_close(channel["buffer"])

            connect(server, servers[server])
        except ssl.SSLWantReadError:
            # not sure what to do here.
            # it doesn't seem to affect execution much so I'll just ignore it
            # todo: figure out what this means
            weechat.prnt("", "weecent\ti got that darn ssl error again")

    return weechat.WEECHAT_RC_OK
Exemplo n.º 19
0
def samegame_input_buffer(data, buffer, input):
    """Input data in samegame buffer."""
    global samegame
    if input:
        args = input.split(' ')
        if args[0] in ('n', 'new'):
            samegame_new_game()
        elif args[0] in ('q', 'quit'):
            weechat.buffer_close(samegame['buffer'])
        elif args[0] == '+':
            samegame_change_size(+1)
        elif args[0] == '-':
            samegame_change_size(-1)
        elif args[0].isdigit():
            numcolors = int(args[0])
            if numcolors >= 3 and numcolors <= 6:
                samegame['numcolors'] = numcolors
                samegame_new_game()
    return weechat.WEECHAT_RC_OK
Exemplo n.º 20
0
def samegame_input_buffer(data, buffer, input):
    """Input data in samegame buffer."""
    global samegame
    if input:
        args = input.split(" ")
        if args[0] in ("n", "new"):
            samegame_new_game()
        elif args[0] in ("q", "quit"):
            weechat.buffer_close(samegame["buffer"])
        elif args[0] == "+":
            samegame_change_size(+1)
        elif args[0] == "-":
            samegame_change_size(-1)
        elif args[0].isdigit():
            numcolors = int(args[0])
            if numcolors >= 3 and numcolors <= 6:
                samegame["numcolors"] = numcolors
                samegame_new_game()
    return weechat.WEECHAT_RC_OK
Exemplo n.º 21
0
def infolist_buffer_input_cb(data, buffer, input_data):
    if input_data == "q" or input_data == "Q":
        weechat.buffer_close(buffer)
    else:
        infolist_display(buffer, input_data)
    return weechat.WEECHAT_RC_OK
Exemplo n.º 22
0
 def delete(self):
     if self.buffer is not None:
         return weechat.buffer_close(self.buffer)
     self.server.chats.remove(self)
Exemplo n.º 23
0
 def delete(self) :
     if self.buffer is not None :
         return weechat.buffer_close(self.buffer)
     self.server.chats.remove(self)
Exemplo n.º 24
0
def urlserver_buffer_input_cb(data, buffer, input_data):
    if input_data in ('q', 'Q'):
        weechat.buffer_close(buffer)
    return weechat.WEECHAT_RC_OK
Exemplo n.º 25
0
 def detach_buffer(self):
     if self.channel_buffer != None:
         w.buffer_close(self.channel_buffer)
         self.channel_buffer = None
Exemplo n.º 26
0
def nameday_buffer_input_cb(data, buffer, input_data):
    """Input callback for buffer."""
    if input_data.lower() == 'q':
        weechat.buffer_close(buffer)
    return weechat.WEECHAT_RC_OK
Exemplo n.º 27
0
 def close(self):
     if self._pointer:
         weechat.buffer_close(self._pointer)
Exemplo n.º 28
0
 def close(self):
     buffer = weechat.buffer_search('python', self.__name__)
     if buffer:
         weechat.buffer_close(buffer)
Exemplo n.º 29
0
 def detach_buffer(self):
     if self.channel_buffer != None:
         w.buffer_close(self.channel_buffer)
         self.channel_buffer = None
Exemplo n.º 30
0
def infolist_buffer_input_cb(data, buffer, input_data):
    if input_data == "q" or input_data == "Q":
        weechat.buffer_close(buffer)
    else:
        infolist_display(buffer, input_data)
    return weechat.WEECHAT_RC_OK
Exemplo n.º 31
0
def buffer_input_cb(data, buf, input_data):
    """Input on weetris buffer."""
    if input_data == 'q':
        weechat.buffer_close(weetris['buffer'])
    return weechat.WEECHAT_RC_OK
Exemplo n.º 32
0
def urlserver_buffer_input_cb(data, buffer, input_data):
    if input_data in ('q', 'Q'):
        weechat.buffer_close(buffer)
    return weechat.WEECHAT_RC_OK
Exemplo n.º 33
0
def exit_cb():
    log_debug('Exiting')
    weechat.buffer_close(BUFFER)

    return weechat.WEECHAT_RC_OK