Exemplo n.º 1
0
 def __init__(self, eb):
     super().__init__()
     self.previous = "Internet Status: Det er ikke registrert noen problemer i ditt område."
     self.eb = eb
     self.eb.register_consumer(self, EVENTID_INTERNET_CHECK)
     self.msg_data = MessageData('',
                                 thread_id=_THREAD_ID,
                                 thread_type=ThreadType.GROUP)
     self.repeating_event = RepeatingEventObject(
         eb, event(EVENTID_INTERNET_CHECK, None), datetime.now(),
         timedelta(minutes=4))
     self.repeating_event.queue()
     print("internet status init")
Exemplo n.º 2
0
    def parseRemindMe(self,message_data):
        text = message_data.get_text().split()

        if(len(text)>1):
            text_time = text[1]
            time_delta = self.get_time_delta_from_text(text_time)
        else:
            message_data.set_text("Please Specify Time: !rm ?w?d?h?m?s")
            FbClient.post_message_event(self.eb,message_data)
            return

        text_message = "REMINDER"
        if(len(text) > 2):
            text_message += ": " +  ' '.join(text[2:])

        message_data.set_text(text_message)
        send_message_event = event(EVENTID_CLIENT_SEND,message_data)
        TimeEventQueuer.post_time_event(self.eb,send_message_event,time_delta)
        
        if(time_delta>timedelta(seconds = 15)):
            time_at = datetime.datetime.now() + time_delta
            reciept_text = "Reminder set at {} in {}".format(
                    (':').join(str(time_at).split(':')[:-1]),
                    str(time_delta).split('.')[0])
            reciept_data = MessageData(reciept_text,message_data.get_id(),
                    message_data.get_type())
            FbClient.post_message_event(self.eb,reciept_data)
Exemplo n.º 3
0
 def __init__(self, eb):
     super().__init__()
     self.eb = eb
     self.eb.register_consumer(self, EVENTID_WEATHER_CHECK)
     self.eb.register_consumer(self, EVENTID_WEATHER_SUBSCRIPTION)
     self.msg_data = MessageData('',
                                 thread_id=_THREAD_ID,
                                 thread_type=ThreadType.GROUP)
     print("Weather Module status Init")
Exemplo n.º 4
0
class InternetStatus(threading.Thread, subscriber):
    def __init__(self, eb):
        super().__init__()
        self.previous = "Internet Status: Det er ikke registrert noen problemer i ditt område."
        self.eb = eb
        self.eb.register_consumer(self, EVENTID_INTERNET_CHECK)
        self.msg_data = MessageData('',
                                    thread_id=_THREAD_ID,
                                    thread_type=ThreadType.GROUP)
        self.repeating_event = RepeatingEventObject(
            eb, event(EVENTID_INTERNET_CHECK, None), datetime.now(),
            timedelta(minutes=4))
        self.repeating_event.queue()
        print("internet status init")

    def process(self, new_event):
        # print("Event Recieved: {}".format(new_event.get_topic()))
        if not isinstance(new_event, event):
            print("Invalid event type passed")
            return
        if (new_event.get_topic() == EVENTID_INTERNET_CHECK):
            self.get_status()

    def get_status(self):
        url = "https://kabel.canaldigital.no/hjelp/sok-etter-feil/?facebook=False&q=7033"
        a = requests.get(url)

        start_str = "class=\"searchresultItem\">"
        end_str = "</h2>"
        start = a.text.find(start_str)
        end = a.text.find(end_str, start)

        s = a.text[start + len(start_str):end]
        s = s.replace("<h2>", "")
        s = s.replace("&#229;", "å")  # superhacky. klarer ikke fikse utf-8
        s = s.strip()
        s = "Internet Status: " + s

        # print("post internet status")
        if s != self.previous:
            self.previous = s
            self.msg_data.set_text(s)
            Fb_client.post_message_event(self.eb, self.msg_data)
Exemplo n.º 5
0
    def resend_by_mask(self, mask, msg: MessageData):
        groups = self._filter_groups(mask)
        msgs = self.sent_messages.setdefault(msg.id, {})

        for group in groups:
            if group in msgs:
                continue

            res = msg.send(self.bot, group)
            msgs[group] = res.message_id

        return len(groups) > 0
Exemplo n.º 6
0
    def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs):
        self.markAsDelivered(author_id, thread_id)
        self.markAsRead(author_id)

        #log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name))

        # If Saitama-san is the author -> sayonara
        if author_id == self.uid:
            return
        message_data = MessageData(message_object.text, thread_id, thread_type)
        self.parser.parse(message_data)
        print("Message parsed")
Exemplo n.º 7
0
def suggest_resend(message: Message) -> None:
    if message.chat.type != 'private':
        return

    admins = bot.get_chat_administrators(config.admin_chat)
    user_id = message.from_user.id
    is_user_admin = any(admin.user.id == user_id for admin in admins)
    if not is_user_admin:
        return

    chat_id = message.chat.id

    # save message
    msg: MessageData = MessageData(message)

    chat = chats.setdefault(chat_id, Chat(chat_id, bot, db))
    chat.messages_to_resend[msg.id] = msg
    chat.suggest_resend(msg.id)
Exemplo n.º 8
0
 def postIp(self):
     ip = socket.gethostbyname(socket.gethostname())
     print("Sending Ip: " + ip)
     data = MessageData(ip,_THREAD_ID,Thread.USER);
     data.show()
     FbClient.post_message_event(self.eb,message_data);