Exemplo n.º 1
0
    def is_name_change(self, match, group_id):
        """
        Changed name in DB on nickname change.
        :param match: re match groups
        """
        user_name = match.group(1).rstrip()
        new_name = match.group(2).rstrip()
        log.info('SYSTEM MATCH: nickname change detected.')

        try:
            member = Group.list().filter(
                group_id=str(group_id))[0].members().filter(
                    nickname=new_name)[0]
            user_id = int(member.user_id)
            log.info('GROUPY: Converted name to ID')

            # check if user already in DB
            if not db.exists(user_id, group_id):
                log.warning('DB: user not found in DB but should have been. '
                            'Probably does not have any points yet.')
                return

        except IndexError:  # fallback to switching by name rather than user_id
            user_id = user_name
            log.warning('GROUPY: Could not find user_id, falling back to '
                        'name.')

        db.change_player_name(new_name, user_id, group_id)

        points = db.get_player_points(user_id, group_id)
        post_text = 'Don\'t worry {}, you still have your {} point(s).'.format(
            new_name, points)

        return post_text
Exemplo n.º 2
0
    def __init__(self, api_key, bot_id):
        config.API_KEY = api_key
        self.bot = GroupyBot.list().filter(bot_id=bot_id).first
        self.group = Group.list().filter(id=self.bot.group_id).first

        self.chatlog = open('logs/{}.log'.format(self.group.name), 'a+')

        self.logger = logging.getLogger(self.bot.name)

        self.generate_triggers()
        self.gather_commands()
Exemplo n.º 3
0
 def connectBot(self):
     try:
         bot = [bot for bot in Bot.list() if bot.bot_id == self.botID][0]
         group = [group for group in Group.list() if group.group_id == self.groupID][0]
         if bot is not None and group is not None:
             self.bot = bot
             self.group = group
             self.currentCommand = str(group.messages().newest.id)
             print("Successfully connected bot")
         else:
             print("Error connecting bot")
     except Exception as e:
         print("Error in connectBot(): " + e.__str__())
Exemplo n.º 4
0
    def is_who(self, text, group_id):
        """
        Response for asking upbot who.
        """
        log.info('MATCH: who in "{}".'.format(text))

        member = Group.list().filter(group_id=str(group_id))[0].members()

        intro = [
            'Signs Point to ', 'Looks like ', 'Winner is ', 'I think it was '
        ]

        post_text = random.choice(intro) + random.choice(member).nickname

        return post_text
Exemplo n.º 5
0
 def connectBot(self):
     try:
         bot = [bot for bot in Bot.list() if bot.bot_id == self.botID][0]
         group = [
             group for group in Group.list()
             if group.group_id == self.groupID
         ][0]
         if bot is not None and group is not None:
             self.bot = bot
             self.group = group
             self.currentCommand = str(group.messages().newest.id)
             print("Successfully connected bot")
         else:
             print("Error connecting bot")
     except Exception as e:
         print("Error in connectBot(): " + e.__str__())
Exemplo n.º 6
0
    def __init__(self):
        configs = Config()
        config.KEY_LOCATION = configs.api_key

        self.config = configs

        self.groupID = configs._groupID
        self.botID = configs._botID
        self.prefix = configs._prefix
        self.nsfw = configs.nsfw
        self.admin = configs.admin
        self.reddit = Reddit("Groupme")
        self.state = RedditBotState.READY

        self.bot = [bot for bot in Bot.list() if bot.bot_id == self.botID][0]
        self.group = [group for group in Group.list() if group.group_id == self.groupID][0]

        self.currentCommand = str(self.getLatestMessage().id)
        self.commandQueue = OrderedDict()
Exemplo n.º 7
0
    def is_new_user(self, match, group_id):
        """
        Response to new user. Welcomes them and adds them to db.
        :param match: re match groups
        """
        user_name = match.group(2)
        log.info('SYSTEM MATCH: new user detected.')

        member = Group.list().filter(
            group_id=str(group_id))[0].members().filter(nickname=user_name)[0]
        user_id = int(member.user_id)

        # check if user already in DB
        if not db.exists(user_id, group_id):
            db.add_player(user_id, user_name, group_id)

        points = db.get_player_points(user_id, group_id)
        post_text = 'Welcome {}. You have {} points.'.format(user_name, points)

        return post_text
Exemplo n.º 8
0
    def __init__(self):
        configs = Config()
        config.KEY_LOCATION = configs.api_key

        self.config = configs

        self.groupID = configs._groupID
        self.botID = configs._botID
        self.prefix = configs._prefix
        self.nsfw = configs.nsfw
        self.admin = configs.admin
        self.reddit = Reddit("Groupme")
        self.state = RedditBotState.READY

        self.bot = [bot for bot in Bot.list() if bot.bot_id == self.botID][0]
        self.group = [
            group for group in Group.list() if group.group_id == self.groupID
        ][0]

        self.currentCommand = str(self.getLatestMessage().id)
        self.commandQueue = OrderedDict()
Exemplo n.º 9
0
    def sub_point(self, id, group_id):
        """
        Adds point to player by name or id.
        :param id: player name or id
        :return: players points as int
        """
        # see if points_to is a person, get groupme ID if so
        try:
            member = Group.list().filter(
                group_id=group_id)[0].members().filter(nickname=id)[0]

            id = int(member.user_id)
            log.info('GROUPY: Converted name to ID')

        except (TypeError, IndexError):
            pass

        if type(id) == int:
            sql = "UPDATE \"{}\" SET points = points - 1 WHERE id={}"

        else:
            sql = "UPDATE \"{}\" SET points = points - 1 WHERE " \
                  "LOWER(name)=LOWER('{}')"

        if self.con is not None:
            try:
                # get points first because this checks if exists or not
                cur_points = self.get_player_points(id, group_id)
                self.cur.execute(sql.format(group_id, id))
                self.con.commit()
                log.info('SUB: point to {}; now has {} point(s).'.format(
                    id, cur_points - 1))
                return cur_points - 1

            except psycopg2.DatabaseError as e:
                self.con.rollback()
                log.error(e)

        else:
            log.error('Failed adding points: not connected to DB.')
Exemplo n.º 10
0
def groupme_bot():
    sentenceList = []
    group = Group.list().first
    messages = group.messages()
    message = str(messages.newest)

    regex = r"(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9]\.[^\s]{2,})"
    #regex = r"(\s*(.+?)(?:\s+(\d+)(?:(?:\s+\(?of\s+|-)(\d+)\)?)?)?|(\w+)): (https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-ZA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9]\.[^\s]{2,})"

    bot = Bot.list().first

    LANGUAGE = "english"
    SENTENCES_COUNT = 3

    matches = re.finditer(regex, message)

    bot.post("Beginning the TL;DR summary:")
    for matchNum, match in enumerate(matches):
        matchNum += 1
        url = str(match.group(1))
        parser = HtmlParser.from_url(url, Tokenizer(LANGUAGE))
        stemmer = Stemmer(LANGUAGE)
        summarizer = Summarizer(stemmer)
        summarizer.stop_words = get_stop_words(LANGUAGE)
        start = default_timer()

        for sentence in summarizer(parser.document, SENTENCES_COUNT):
            sentenceList.append(str(sentence))

    print(sentenceList)
    bot.post(
        str(sentenceList).replace("[", "").replace("]", "").replace(
            "'", "").replace("\\n", " ").replace(".,", "."))
    duration = default_timer() - start
    bot.post("Time to complete this TL;DR summary: " +
             '{:.2f}'.format(float(duration)) + " seconds")
    print("Successfully completed!")
Exemplo n.º 11
0
    def new_id(self, group_id, id=None):
        """
        Generates new IDs for non players that need points
        :return: new random int
        """
        if id is not None:
            try:
                member = Group.list().filter(
                    group_id=str(group_id))[0].members().filter(nickname=id)[0]
                id = int(member.user_id)
                log.info('ID: Got ID from Groupme. #{}'.format(id))

            except IndexError:
                id = None

        not_taken = False

        sql = "SELECT * FROM \"{}\" WHERE id={}"

        if id is None:
            while not not_taken:
                try:
                    id = randint(9999999, 100000000)
                    self.cur.execute(sql.format(group_id, id))
                    ret = self.cur.fetchone()
                    if ret is None:
                        not_taken = True

                except psycopg2.DatabaseError as e:
                    log.error(e)
                    break

        if not_taken:
            log.info('ID: Got ID from random. #{}'.format(id))

        return id
Exemplo n.º 12
0
import GetScores
import os
from groupy import Group, Bot

# list of my GroupMe groups
groups = Group.list()

botId = os.getenv('botId')
print(botId)
groupId = '33275265'
full_text = ''
league_id = '458388'
season_id = '2017'
league_size = 16

# loop through GroupMe Groups and find desired group based off the group id.
for g in groups:
    if g.group_id == groupId:
        group = g

# assign the bot to the correct bot ID from the bot list
for bot in Bot.list():
    if bot.bot_id == botId:
        testBot = bot

# bot setup to print what is desired within the groupme

#testBot.post("test")


def send_message(full_text):
Exemplo n.º 13
0
def get_group(groupID):
    for g in Group.list():
        if g.group_id == groupID:
            return g
Exemplo n.º 14
0
from groupy import Member, Bot, Group
from random import randint

group = Group.list()[0]
bot = Bot.list().first
members = group.members()

rating = [
    "I rate your meme: shitpost",
    "I rate your meme: 0/10 f**k you",
    "I rate your meme: God tier",
    "I rate your meme: perfect 5/7",
    "I rate your meme: gr8 8/8",
    "I rate your meme: 2/10, 6/10 with rice",
]


def MemeBot(message):
    if "Try these commands:" in message:
        return
    elif "Damn straight I'm Canadian" in message:
        return
    elif "!ratememe" in message:
        ind = randint(0, 5)
        bot.post(rating[ind])
    elif "lol" in message:
        bot.post("That wasn't funny you asshole")
    elif "!help" in message:
        bot.post("There's no help for you, anon")
    elif "!actualhelp" in message:
        bot.post("Try these commands: '!help', '!roll', '!ratememe', !pickasshole")