Example #1
0
    def connect(self, cmd, con, nick):
        '''
        Called when the user has issued a wish to connect.
        Determines next action by checking the rest of the user's input and
        if the user is authorized to connect.
        '''
        if(not self.val_users.is_validated(nick)):
            con.privmsg(nick, "You are not validated and may not " +
                        "connect. Type 'help validate' for instructions.")
            return

        # This regexp returns a string array of words, which it parses by
        # seperating them by whitespace.
        words = [p for p in re.split("( |\\\".*?\\\"|'.*?')", cmd) if p.strip()]
        # Set the default port in case the user does not specify one
        port = 6667
        if(len(words) < 3):
            con.privmsg(nick, "You supplied too few arguments (at least"
            + " two needed), type 'help connect' for more info.")
            return

        server =  words[2] # Server should be the second argument
        serverban = self.ban_han.is_banned_from_server(
                self.val_users.get_pseudonym(nick), server)
        if (serverban):
            con.privmsg(nick, "ERROR: You are banned from " +
                            "this server.")
            return
        try:
            if (words[3]): #If the user has specified a port, we use that instead
                if(re.match("[0-9]+", words[3])):
                    port = int(words[3])
                else:
                    con.privmsg(nick, "Port cannot contain anything " +
                            "but numbers. Try again. For help type 'help connect'")
                    return
        except IndexError:
            pass
        #words[1] is the nick
        event.connect(nick, server, port, words[1])

# Tell the user what happened
        if(words[2]):
            con.privmsg(nick, "Connecting you to " + server +
            " at port " + str(port) +  ". You should now be able " +
            "to join a channel. Do so as you normally would.")
            return
        #TODO: Implement nick functionality to the connect statement
        else:
            con.privmsg(nick, "You specified no port, defaulting to port " +
                        str(port) + ". You should now be able to join a " +
                        "channel. Do so as you normally would.")
            return

        # If function is still running, something has gone wrong
        con.privmsg(nick, "Something went wrong, please " +
                    "contact the system administrator.")
Example #2
0
def bind_key(event_type, wid, key_string, cb):
    """
    Binds a function ``cb`` to a particular key press ``key_string`` on a
    window ``wid``. Whether it's a key release or key press binding is
    determined by ``event_type``.

    ``bind_key`` will automatically hook into the ``event`` module's dispatcher,
    so that if you're using ``event.main()`` for your main loop, everything
    will be taken care of for you.

    :param event_type: Either 'KeyPress' or 'KeyRelease'.
    :type event_type: str
    :param wid: The window to bind the key grab to.
    :type wid: int
    :param key_string: A string of the form 'Mod1-Control-a'.
                       Namely, a list of zero or more modifiers separated by
                       '-', followed by a single non-modifier key.
    :type key_string: str
    :param cb: A first class function with no parameters.
    :type cb: function
    :return: True if the binding was successful, False otherwise.
    :rtype: bool
    """
    assert event_type in ('KeyPress', 'KeyRelease')

    mods, kc = parse_keystring(key_string)
    key = (wid, mods, kc)

    if not kc:
        print >> sys.stderr, 'Could not find a keycode for %s' % key_string
        return False

    if not __keygrabs[key] and not grab_key(wid, mods, kc):
        return False

    __keybinds[key].append(cb)
    __keygrabs[key] += 1

    if not event.is_connected(event_type, wid, __run_keybind_callbacks):
        event.connect(event_type, wid, __run_keybind_callbacks)

    return True
Example #3
0
def bind_key(event_type, wid, key_string, cb):
    """
    Binds a function ``cb`` to a particular key press ``key_string`` on a
    window ``wid``. Whether it's a key release or key press binding is
    determined by ``event_type``.

    ``bind_key`` will automatically hook into the ``event`` module's dispatcher,
    so that if you're using ``event.main()`` for your main loop, everything
    will be taken care of for you.

    :param event_type: Either 'KeyPress' or 'KeyRelease'.
    :type event_type: str
    :param wid: The window to bind the key grab to.
    :type wid: int
    :param key_string: A string of the form 'Mod1-Control-a'.
                       Namely, a list of zero or more modifiers separated by
                       '-', followed by a single non-modifier key.
    :type key_string: str
    :param cb: A first class function with no parameters.
    :type cb: function
    :return: True if the binding was successful, False otherwise.
    :rtype: bool
    """
    assert event_type in ('KeyPress', 'KeyRelease')

    mods, kc = parse_keystring(key_string)
    key = (wid, mods, kc)

    if not kc:
        print >> sys.stderr, 'Could not find a keycode for %s' % key_string
        return False

    if not __keygrabs[key] and not grab_key(wid, mods, kc):
        return False

    __keybinds[key].append(cb)
    __keygrabs[key] += 1

    if not event.is_connected(event_type, wid, __run_keybind_callbacks):
        event.connect(event_type, wid, __run_keybind_callbacks)

    return True
import os
from dotenv import load_dotenv
import event
import asyncio
from asgiref.sync import async_to_sync


def print_camion():
    print("camion")


def print_something(something: str):
    print(something)


event.connect("camion_registered", print_camion)
event.connect("camion_registered", print_something)


async def trigger_camion_registered():
    await event.trigger("camion_registered", "something about trucks")


print("async_to_sync ...")
async_to_sync(trigger_camion_registered)()


def token_print():
    load_dotenv()
    print("TOKEN", os.getenv("TOKEN"))
Example #5
0
    key = (e.event, mods, kc)
    for cb in __keybinds.get(key, []):
        try:
            cb(e)
        except TypeError:
            cb()

def __regrab(changes):
    """
    Takes a dictionary of changes (mapping old keycode to new keycode) and
    regrabs any keys that have been changed with the updated keycode.

    :param changes: Mapping of changes from old keycode to new keycode.
    :type changes: dict
    :rtype: void
    """
    for wid, mods, kc in __keybinds.keys():
        if kc in changes:
            ungrab_key(wid, mods, kc)
            grab_key(wid, mods, changes[kc])

            old = (wid, mods, kc)
            new = (wid, mods, changes[kc])
            __keybinds[new] = __keybinds[old]
            del __keybinds[old]

update_keyboard_mapping(None)
event.connect('MappingNotify', None, update_keyboard_mapping)

Example #6
0
    key = (e.event, mods, kc)
    for cb in __keybinds.get(key, []):
        try:
            cb(e)
        except TypeError:
            cb()

def __regrab(changes):
    """
    Takes a dictionary of changes (mapping old keycode to new keycode) and
    regrabs any keys that have been changed with the updated keycode.

    :param changes: Mapping of changes from old keycode to new keycode.
    :type changes: dict
    :rtype: void
    """
    for wid, mods, kc in __keybinds:
        if kc in changes:
            ungrab_key(wid, mods, kc)
            grab_key(wid, mods, changes[kc])

            old = (wid, mods, kc)
            new = (wid, mods, changes[kc])
            __keybinds[new] = __keybinds[old]
            del __keybinds[old]

if conn is not None:
    update_keyboard_mapping(None)
    event.connect('MappingNotify', None, update_keyboard_mapping)