Ejemplo n.º 1
0
Archivo: bot.py Proyecto: MeGaTG/pybot
def match_plugin(plugin, name, msg):
    if not hasattr(msg, 'text') or not msg.text or msg.text == '':
        return
    receiver = utils.get_receiver(msg)
    text = msg.text
    patterns = utils.get_infov(plugin, 'patterns', ())
    for pattern in patterns:
        # print("Trying to match", pattern, "with", text)
        matches = utils.match_pattern(pattern, text)
        if not matches:
            continue
        print("Message matches: {}".format(pattern))

        if utils.is_plugin_disabled_on_chat(name, receiver):
            return None

        if not utils.plugin_have_obj(plugin, 'run'):
            print("The plugin {} don't have run function".format(name))
            continue
        if utils.warns_user_not_allowed(plugin, msg):
            continue
        result = utils.execute_plugin_function_obj(plugin, 'run', msg, matches)
        if result and type(result) == str:
            utils.send_large_msg(receiver, result)
        return  # Only one pattern per plugin!
Ejemplo n.º 2
0
def match_plugin(plugin, name, msg):
    if not hasattr(msg, 'text') or not msg.text or msg.text == '':
        return
    receiver = utils.get_receiver(msg)
    text = msg.text
    patterns = utils.get_infov(plugin, 'patterns', ())
    for pattern in patterns:
        # print("Trying to match", pattern, "with", text)
        matches = utils.match_pattern(pattern, text)
        if not matches:
            continue
        print("Message matches: {}".format(pattern))

        if utils.is_plugin_disabled_on_chat(name, receiver):
            return None

        if not utils.plugin_have_obj(plugin, 'run'):
            print("The plugin {} don't have run function".format(name))
            continue
        if utils.warns_user_not_allowed(plugin, msg):
            continue
        result = utils.execute_plugin_function_obj(plugin, 'run', msg, matches)
        if result and type(result) == str:
            utils.send_large_msg(receiver, result)
        return  # Only one pattern per plugin!
Ejemplo n.º 3
0
def run(msg, matches):
    receiver = utils.get_receiver(msg)
    exp = matches[0]
    path = "http://api.mathjs.org/v1/"
    payload = {'expr': exp}
    if len(matches) > 1:
        payload.update({'precision': matches[1]})
    gcb = utils.gac(cb, receiver)
    utils.mp_requests('GET', path, gcb, params=payload)
Ejemplo n.º 4
0
def run(msg, matches):
    receiver = utils.get_receiver(msg)
    exp = matches[0]
    path = "http://api.mathjs.org/v1/"
    payload = {'expr': exp}
    if len(matches) > 1:
        payload.update({'precision': matches[1]})
    gcb = utils.gac(cb, receiver)
    utils.mp_requests('GET', path, gcb, params=payload)
Ejemplo n.º 5
0
def pre_process(msg):
    receiver = utils.get_receiver_id(msg)
    if utils.is_sudo(msg) and msg.text == "!channel enable":
        peer = utils.get_receiver(msg)
        enable_channel(receiver)
        peer.send_msg("Channel enabled")
        return None  # Already processed
    conf = utils.get_safe_setting('disabled_channels', list)
    if receiver in conf:
        return None  # Don't process the message
    return msg
Ejemplo n.º 6
0
def run(msg, matches):
    url = matches[0]
    ext = matches[1]
    receiver = utils.get_receiver(msg)
    # Using thread... It's not really good
    # utils.async_download_to_file(url, ext, async_callback_download, receiver)
    # Using multiprocessing
    # First create a generic callback
    gcb = utils.generic_async_callback(async_callback_download, ext, receiver)
    # Then use the mp download
    utils.mp_download_to_file(url, ext, gcb, receiver)
Ejemplo n.º 7
0
Archivo: bot.py Proyecto: MeGaTG/pybot
def on_msg_receive(msg):
    global started
    if not started:
        return
    talkoneself = settings.TALK_ONESELF if hasattr(settings, 'TALK_ONESELF') else False
    receiver = utils.get_receiver(msg)
    # pp.pprint(msg)
    # pp.pprint(receiver)
    if msg_valid(msg):
        msg = _internal_preproc(msg)
        msg = pre_process_msg(msg)
        if msg:
            match_plugins(msg)
            if not talkoneself:  # Only mark as read if we don't let us talk to ourself (means that we are the bot)
                receiver.mark_read(utils.ok_gen)
Ejemplo n.º 8
0
 def run(self, msg, matches):
     receiver = utils.get_receiver(msg)
     pattern = matches[0]
     userid = msg.src.id
     if pattern == "photo" or pattern == "document":
         if userid in self.users:
             # Check if he is in the list
             cb = utils.gac(self.callback, receiver, userid)
             getattr(msg, "load_{}".format(pattern))(cb)
     if pattern == "start":
         self.users.add(userid)
         return "You can send me an image now :)"
     if pattern == "stop":
         if userid in self.users:
             self.users.remove(userid)
Ejemplo n.º 9
0
def run(msg, matches):
    receiver = utils.get_receiver(msg)
    print()
    if len(matches) == 1:
        if matches[0] == "!id":
            return user_id(msg)
        elif matches[0] == 'chat':
            if not utils.is_chat_msg(msg):
                return 'You are not in a chat'
            else:
                receiver.info(callback)
    elif len(matches) == 2:
        return "Not implemented yet the function necesary in tgl :'('"
    # Implement your run function here
    return ""
Ejemplo n.º 10
0
def run(msg, matches):
    receiver = utils.get_receiver(msg)
    print()
    if len(matches) == 1:
        if matches[0] == "!id":
            return user_id(msg)
        elif matches[0] == 'chat':
            if not utils.is_chat_msg(msg):
                return 'You are not in a chat'
            else:
                receiver.info(callback)
    elif len(matches) == 2:
        return "Not implemented yet the function necesary in tgl :'('"
    # Implement your run function here
    return ""
Ejemplo n.º 11
0
def match_plugin(plugin, name, msg):
    if not hasattr(msg, 'text') or not msg.text or msg.text == '':
        return
    receiver = utils.get_receiver(msg)
    text = msg.text
    patterns = utils.get_infov(plugin, 'patterns', ())
    for pattern in patterns:
        # print("Trying to match", pattern, "with", text)
        matches = utils.match_pattern(pattern, text)
        if not matches:
            continue
        print("Message matches: {}".format(pattern))

        if utils.is_plugin_disabled_on_chat(name, receiver):
            return None
Ejemplo n.º 12
0
def on_msg_receive(msg):
    global started
    if not started:
        return
    talkoneself = settings.TALK_ONESELF if hasattr(settings, 'TALK_ONESELF') else False
    receiver = utils.get_receiver(msg)
    # pp.pprint(msg)
    # pp.pprint(receiver)
    if msg_valid(msg):
        msg = _internal_preproc(msg)
        msg = pre_process_msg(msg)
        if msg:
            match_plugins(msg)
            if not talkoneself:  # Only mark as read if we don't let us talk to ourself (means that we are the bot)
                receiver.mark_read(utils.ok_gen)
Ejemplo n.º 13
0
def run(msg, matches):
    currencies = [
        "AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN",
        "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL",
        "BSD", "BTC", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHF", "CLF",
        "CLP", "CNH", "CNY", "COP", "CRC", "CUP", "CVE", "CZK", "DEM", "DJF",
        "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FIM", "FJD", "FKP",
        "FRF", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD",
        "HNL", "HRK", "HTG", "HUF", "IDR", "IEP", "ILS", "INR", "IQD", "IRR",
        "ISK", "ITL", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW",
        "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL",
        "LVL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO",
        "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK",
        "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKG", "PKR", "PLN",
        "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG",
        "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "STD", "SVC", "SYP", "SZL",
        "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH",
        "UGX", "USD", "UYU", "UZS", "VEF", "VND", "VUV", "WST", "XAF", "XCD",
        "XDR", "XOF", "XPF", "YER", "ZAR", "ZMK", "ZMW", "ZWL"
    ]

    fromCur = matches[0].upper()
    amount = matches[1]
    toCur = matches[2].upper()

    if fromCur.isdigit():
        fromCur, amount = amount.upper(), fromCur

    if fromCur not in currencies:
        return "ERROR: currency \"" + fromCur + "\" is not recognized"

    if toCur not in currencies:
        return "ERROR: currency \"" + toCur + "\" is not recognized"

    url = "https://www.google.com/finance/converter?a=" + \
          amount + "&from=" + fromCur + "&to=" + toCur

    receiver = utils.get_receiver(msg)

    gcb = utils.gac(cb, receiver, amount, fromCur, toCur)
    utils.mp_requests('GET', url, gcb)
Ejemplo n.º 14
0
def run(msg, matches):
    currencies = ["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTC", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHF", "CLF", "CLP", "CNH", "CNY", "COP", "CRC", "CUP", "CVE", "CZK", "DEM", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FIM", "FJD", "FKP", "FRF", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "IEP", "ILS", "INR", "IQD", "IRR", "ISK", "ITL", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LVL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKG", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "STD", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VEF", "VND", "VUV", "WST", "XAF", "XCD", "XDR", "XOF", "XPF", "YER", "ZAR", "ZMK", "ZMW", "ZWL"]

    fromCur = matches[0].upper()
    amount = matches[1]
    toCur = matches[2].upper()

    if fromCur.isdigit():
        fromCur, amount = amount.upper(), fromCur

    if fromCur not in currencies:
        return "ERROR: currency \"" + fromCur + "\" is not recognized"

    if toCur not in currencies:
        return "ERROR: currency \"" + toCur + "\" is not recognized"

    url = "https://www.google.com/finance/converter?a=" + \
          amount + "&from=" + fromCur + "&to=" + toCur

    receiver = utils.get_receiver(msg)

    gcb = utils.gac(cb, receiver, amount, fromCur, toCur)
    utils.mp_requests('GET', url, gcb)