Exemplo n.º 1
0
def tag_all(client, author_id, message_object, thread_id, thread_type):
    gc_thread = Client.fetchThreadInfo(client, thread_id)[thread_id]
    mention_list = []
    message_text = '@all'
    for person in Client.fetchAllUsersFromThreads(self=client,
                                                  threads=[gc_thread]):
        mention_list.append(Mention(thread_id=person.uid, offset=0, length=1))
    client.send(Message(text=message_text, mentions=mention_list),
                thread_id=thread_id,
                thread_type=thread_type)
Exemplo n.º 2
0
def make_friend(client, author_id, message_object, thread_id, thread_type):
    gc_thread = Client.fetchThreadInfo(client, thread_id)[thread_id]
    person_to_friend = message_object.text.split(' ', 1)[1]
    for person in Client.fetchAllUsersFromThreads(self=client,
                                                  threads=[gc_thread]):
        if person_to_friend.lower() in person.name.lower():
            action_queue.put(
                Action(client,
                       'makefriend',
                       thread_id,
                       thread_type,
                       pid=person.uid))
Exemplo n.º 3
0
def kick_random(client, author_id, message_object, thread_id, thread_type):
    """Kicks a random person from the chat"""
    gc_thread = Client.fetchThreadInfo(client, thread_id)[thread_id]
    persons_list = Client.fetchAllUsersFromThreads(self=client,
                                                   threads=[gc_thread])
    num = random.randint(0, len(persons_list) - 1)  #random number within range
    person = persons_list[num]
    log.info("{} removed {} from {}".format(author_id, "random", thread_id))
    action_queue.put(
        Action(client, 'removeuser', thread_id, thread_type, pid=person.uid))
    return
    log.info("Unable to remove: person not found.")
Exemplo n.º 4
0
def kick(client, author_id, message_object, thread_id, thread_type):
    gc_thread = Client.fetchThreadInfo(client, thread_id)[thread_id]
    person_to_kick = message_object.text.split(' ')[1:]
    for person in Client.fetchAllUsersFromThreads(self=client,
                                                  threads=[gc_thread]):
        names = [person.first_name, person.last_name, person.nickname]
        if any([name in person_to_kick for name in names]):
            log.info("{} removed {} from {}").format(author_id, person_to_kick,
                                                     thread_id)
            Client.removeUserFromGroup(user_id=person.uid, thread_id=thread_id)
            return
    log.info("Unable to remove: person not found.")
Exemplo n.º 5
0
def pm_person(client, author_id, message_object, thread_id, thread_type):
    gc_thread = Client.fetchThreadInfo(client, thread_id)[thread_id]
    person_to_pm = message_object.text.split(' ')[1:]
    for person in Client.fetchAllUsersFromThreads(self=client,
                                                  threads=[gc_thread]):
        names = [person.first_name, person.last_name, person.nickname]
        if any([name in person_to_pm for name in names]):
            thread_id = person.uid
    action_queue.put(
        Action(client,
               'message',
               thread_id,
               ThreadType.USER,
               text="hello friend"))
Exemplo n.º 6
0
def tag_all(client, author_id, message_object, thread_id, thread_type):
    """Tags everyone in the chat"""
    gc_thread = Client.fetchThreadInfo(client, thread_id)[thread_id]
    mention_list = []
    message_text = '@all'
    for person in Client.fetchAllUsersFromThreads(self=client,
                                                  threads=[gc_thread]):
        mention_list.append(Mention(thread_id=person.uid, offset=0, length=1))
    action_queue.put(
        Action(client,
               'message',
               thread_id,
               thread_type,
               text=message_text,
               mentions=mention_list))
Exemplo n.º 7
0
def admin(client, author_id, message_object, thread_id, thread_type):
    gc_thread = Client.fetchThreadInfo(client, thread_id)[thread_id]
    person_to_admin = message_object.text.split(' ', 1)[1]
    for person in Client.fetchAllUsersFromThreads(self=client,
                                                  threads=[gc_thread]):
        if person_to_admin.lower() in person.name.lower():
            log.info("{} added as admin {} from {}".format(
                author_id, person_to_admin, thread_id))
            action_queue.put(
                Action(client,
                       'makeadmin',
                       thread_id,
                       thread_type,
                       pid=person.uid))
            return
    log.info("Unable to add admin: person not found.")
Exemplo n.º 8
0
def handle_meeting_vote(client, author_id, poll, thread_id, thread_type):
    global meeting_polls
    global CONSENSUS_THRESHOLD
    gc_thread = Client.fetchThreadInfo(client, thread_id)[thread_id]

    # update meeting_polls by checking today's date, and prune any that've passed
    today = date.today()
    for poll_uid in list(meeting_polls.keys()):
        if meeting_polls[poll_uid]['date'].date() < today:
            meeting_polls.pop(poll_uid)

    # check poll for consensus, i.e majority of users. If so, send update and deactivate poll
    n_users = float(
        len(Client.fetchAllUsersFromThreads(self=client, threads=[gc_thread])))
    check_consensus = lambda votes: (votes / n_users) >= CONSENSUS_THRESHOLD
    consensus = [
        check_consensus(float(option.votes_count))
        for option in client.fetchPollOptions(poll.uid)
    ]
    if any(consensus[:-1]):  # meeting is happening
        meeting_time = client.fetchPollOptions(
            poll.uid)[consensus.index(True)].text
        meeting_date = datetime.strftime(meeting_polls[poll.uid]['date'],
                                         '%A, %x')
        action_queue.put(
            Action(
                client,
                'message',
                thread_id,
                thread_type,
                text=
                f'Consensus reached! Meeting at {meeting_time} on {meeting_date}'
            ))
        return
    elif consensus[-1]:  # meeting is not happening
        action_queue.put(
            Action(
                client,
                'message',
                thread_id,
                thread_type,
                text=
                f'Consensus reached! Meeting at {meeting_time} isn\'t happening.'
            ))
        return
    else:
        log.info(f"No consensus on poll {poll.uid} yet.")
Exemplo n.º 9
0
def kick(client, author_id, message_object, thread_id, thread_type):
    """Kicks the specified user from the chat"""
    gc_thread = Client.fetchThreadInfo(client, thread_id)[thread_id]
    person_to_kick = message_object.text.split(' ', 1)[1]
    for person in Client.fetchAllUsersFromThreads(self=client,
                                                  threads=[gc_thread]):
        if person_to_kick.lower() in person.name.lower():
            log.info("{} removed {} from {}".format(author_id, person_to_kick,
                                                    thread_id))
            action_queue.put(
                Action(client,
                       'removeuser',
                       thread_id,
                       thread_type,
                       pid=person.uid))
            return
    log.info("Unable to remove: person not found.")
Exemplo n.º 10
0
def random_mention(client, author_id, message_object, thread_id, thread_type):
    """Tags a random person"""
    random.seed(time.time())
    gc_thread = Client.fetchThreadInfo(client, thread_id)[thread_id]
    person_list = []
    for person in Client.fetchAllUsersFromThreads(self=client,
                                                  threads=[gc_thread]):
        person_list.append(person)
    chosen_number = random.randrange(0, len(person_list), 1)
    chosen_person = person_list[chosen_number]
    person_name = chosen_person.first_name
    rand_mention = Mention(thread_id=chosen_person.uid,
                           offset=0,
                           length=len(person_name) + 1)
    action_queue.put(
        Action(client,
               'message',
               thread_id,
               thread_type,
               text="@" + person_name + " you have been chosen",
               mentions=[rand_mention]))
Exemplo n.º 11
0
def odds(client, author_id, message_object, thread_id, thread_type):
    # if message contains bracket - is a reply
    hash_search = target = re.match(r"[^[]*\[([^]]*)\]",
                                    message_object.text).groups()
    gc_thread = Client.fetchThreadInfo(client, thread_id)[thread_id]
    if len(hash_search) == 0:  # message contains people - is start of new game
        # make sure game is started in group chat
        if thread_type != ThreadType.GROUP:
            action_queue.put(
                Action(client,
                       'message',
                       thread_id,
                       thread_type,
                       text='Please only do this is a group chat.'))
            return
        new_hash = shake_256(
            str(int(author_id) +
                random.randint(-1e4, 1e4)).encode('utf-8')).hexdigest(6)
        instigator = client.fetchUserInfo(author_id)[author_id]
        # find user
        person_to_friend = message_object.text.split(' ', 1)[1]
        target = None
        for person in Client.fetchAllUsersFromThreads(self=client,
                                                      threads=[gc_thread]):
            if person_to_friend.lower in person.name.lower():
                target = person.uid
        if target == None:
            # tell the user they're dumb
            return
        action_queue.put(
            Action(
                client,
                'message',
                target.uid,
                ThreadType.USER,
                text=
                f"You've been challenged to an odds game by {instigator.first_name}. Pick a number between 1 and 10. To reply, copy and send the message below."
            ))
        action_queue.put(
            Action(client,
                   'message',
                   target.uid,
                   ThreadType.USER,
                   text=f"!odds [{new_hash}] <your number here>"))
        action_queue.put(
            Action(
                client,
                'message',
                instigator.uid,
                ThreadType.USER,
                text=
                f"You started an odds game with {target.first_name}. Pick a number between 1 and 10. To reply, copy and send the message below."
            ))
        action_queue.put(
            Action(client,
                   'message',
                   instigator.uid,
                   ThreadType.USER,
                   text=f"!odds [{new_hash}] <your number here>"))
    else:  # if message contains bracket - is a reply
        # check hashcode against database
        # check if both slots in the hashcode are filled
        if '''both slots are filled''':
            action_queue.put(
                Action(
                    client,
                    'message',
                    gc_thread,
                    ThreadType.GROUP,
                    text=
                    f'{winner.first_name} has won the odds. Do what you will.')
            )