Example #1
0
 def refreshBot(self):
     bots = Bot.list()
     for bot in bots:
         if self.m_thisGroup.id == bot.gorup_id:
             self.m_thisBot = bot
             break
     if self.m_thisBot is None:
         utils.showOutput("Cannot find bot for group {0}".format(groupName), verbosity=utils.INFO_LEVEL_Important)
         sys.exit(0)
Example #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()
Example #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__())
Example #4
0
def start():
    # get groupme API key
    groupy_key = os.environ['GROUPY_KEY']
    config.API_KEY = groupy_key

    group_ids = [int(i.group_id) for i in Bot.list()]
    posts = [i.post for i in Bot.list()]
    names = Bot.list()

    # nested dict of group_id, with post method and bot name
    # eg: {23373961: {'post': <post method>, 'name': 'upbot'}}
    bots = dict(
        zip(group_ids,
            [dict(zip(['post', 'name'], i)) for i in zip(posts, names)]))

    # start server
    server = UpbotServer()
    # GLOBALS ARE BAD
    # TODO: make a class to handle startup and restarting
    global log
    log = server.log

    # initialize bot
    # upbot = GroupMeBot(bot.post)
    global bot
    bot = GroupMeBot(bots)

    # initialize database class
    global db
    db = Database(group_ids)

    # initialize giphy
    giphy = Giphy()
    global gif
    gif = giphy.random

    # init callbacks
    server.setup()
Example #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__())
Example #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()
Example #7
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()
Example #8
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!")
Example #9
0
def get_bot(groupID):
	for b in Bot.list():
		if b.group_id == groupID:
	return b
Example #10
0
import groupy
from groupy import Bot
import time
import hashlib
import configparser
from libbot import *

config = configparser.ConfigParser()
config.read('config.ini')

ADMIN_NAME_HASH = config['DEFAULT'][
    'AdminNameHash']  #MD5 hash of the bot admin's name, they have the power to !kill
TBA_APP_ID = config['DEFAULT']['TBAAppID']
GROUP_NAME = config['DEFAULT']['GroupName']

bot = Bot.list().first
groups = groupy.Group.list()
for i in groups:
    if i.name == GROUP_NAME:
        group = i
oldMsg = ""

while True:
    latestMsg = group.messages().newest
    if latestMsg != oldMsg:
        #print(latestMsg)
        if latestMsg.text == "Hi bot!":
            bot.post("Hi, " + latestMsg.name)
        else:
            cmdname = latestMsg.text.split(" ")[0]
            if cmdname == "!amlookup":
Example #11
0
newGroup = Group.create(oldGroup.name, None, None, False)
newGroup.add(*members)

#get best messages from old group
messages = oldGroup.messages()

stats = []
for mem in members:
    stats.append([mem.user_id, mem.nickname, 0, 0])

while messages.iolder():
    pass

#create bot to post status of old group
StatusBot = Bot.create(
    'StatusBot',
    newGroup,
    avatar_url='https://pbs.twimg.com/media/BtxcH_cIgAAXAC9.jpg')

#count likes per message
for m in messages:
    likes = m.likes()
    likesCount = len(likes)
    sender = m.user_id
    for person in stats:
        if person[0] == sender:
            person[2] += 1
            person[3] += likesCount

#store data in results list
results = []
for s in stats:
Example #12
0
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):
    full_text = GetScores.get_matchup_score(full_text, league_id, season_id,
                                            league_size)
    testBot.post(full_text)


#full_text = GetScores.get_matchup_score(full_text, league_id, season_id, league_size)
Example #13
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")