def setGroup(name): global group groupClient = Client.from_token("KOT8jfdmw8ny42YkOyEE62hiPgkdOWbbD8QZeYu7") groups = list(groupClient.groups.list_all()) for x in groups: if (str(x.name) == name): group = x
def __init__(self, token): self.token = token self.client = Client.from_token(token) self.user_id = self.client.user.me['user_id'] self.chats = [] self.groups = [] self.need_channels = []
def setGroup(name): global group, groupClient groupClient = Client.from_token("----GROUPME_API_TOKEN----") groups = list(groupClient.groups.list_all()) for x in groups: if (str(x.name) == name): group = x
def callback(): token = request.args.get("access_token") c = Client.from_token(token) groups = list(c.groups.list_all()) bots = list(c.bots.list()) ans = "" for group in groups: f = False for bot in bots: if (bot.data["group_id"] == group.data["id"] and bot.data["name"] == "Discord Sync"): ans += f"{group.name} <ol>" f = True if not f: ans += f""" <a href="/groups?id={group.data['id']}&access_token={token}">{group.name} (click to create new bot)</a> <ol> """ for bot in bots: if bot.data["group_id"] == group.data["id"]: ans += f""" <li> <a href="/bots?id={bot.data['bot_id']}&access_token={token}">{bot.data['name']} (edit)</a></li> """ ans += "</ol>" return ans
def getGroup(groupme_key): # groupme_key = os.environ.get("GROUPME_KEY") client = Client.from_token(groupme_key) groups = list(client.groups.list_all()) for group in groups: print(group.name) if group.name == 'Large Fry Larrys': lfl = group return lfl
def funcccccction(): token = request.args.get("access_token") idd = request.args.get("id") delete = bool(request.args.get("delete", False)) c = Client.from_token(token) for bot in c.bots.list(): if idd == bot.data["bot_id"]: if delete: bot.destroy() return redirect(f"/callback?access_token={token}", 301) else: return f"""
def funccccction(): token = request.args.get("access_token") group = request.args.get("id") c = Client.from_token(token) b = c.bots.create( "Discord Sync", group, avatar_url= "https://discord.com/assets/2c21aeda16de354ba5334551a883b481.png", callback_url=mycallback, dm_notification=False, ) return f"""
def token(request): url = request.get_full_path() token = url[39:] f_user = User.objects.get(id=request.user.id) vsbuser = VSBUser.objects.get(user=f_user) for group in GroupMeIntegration.objects.filter(vsb_user=vsbuser): study_group = StudyGroup.objects.get(default_name=group.study_group) client = Client.from_token(token) new_group = client.groups.create(name=study_group.default_name, description="", share=True) study_group.groupme_link = new_group.share_url study_group.save() group.delete() return HttpResponseRedirect(reverse('VSB:account_groups'))
# IMPORTS import os import json import random from urllib.parse import urlencode from urllib.request import Request, urlopen from flask import Flask, request from groupy import Client # Start the app app = Flask(__name__) bot_id = "YOUR BOT ID HERE" # connect to groupme token = 'YOUR TOKEN HERE' client = Client.from_token(token) groups = list(client.groups.list_all()) # make sure the group you're trying to get exists group = None for x in groups: if x.name == 'YOUR GROUP NAME HERE': group = x # adapted from https://github.com/BenDMyers/Boilerplate_GroupMe_Bot # Called whenever the app's callback URL receives a POST request # That'll happen every time a message is sent in the group @app.route('/', methods=['POST']) def webhook(): # 'data' is an object that represents a single GroupMe message.
from groupy import Client import os client = Client.from_token(os.environ.get("GROUPME_API_TOKEN")) def get_group(group_id): return client.groups.get(group_id) def get_user_id_from_group(group_id, nickname): user_id = None group = get_group(group_id) for member in group.members: member_nickname = member.__getattr__("nickname") if member_nickname.lower() == nickname.lower(): user_id = member.__getattr__("user_id") return user_id def update_group_description(group_id, description): group = get_group(group_id) group.update(None, description, os.environ.get("GROUP_PICTURE_URL"), None, False) def upload_picture(file_path): url = None try: with open(file_path, 'rb') as f: url = client.images.upload(f)
if not config_file.is_file(): KEYS.new_config() while KEYS.get_groupme_key() == "": print( "Please enter a GroupMe API Key in config.ini and then press enter to continue" ) time.sleep(1) webbrowser.open('./config.ini') input() except BaseException: print( "Required packages not installed, please run 'pip3 install -r requirements.txt'" ) quit() client = Client.from_token(KEYS.get_groupme_key()) # creates new session (uses api key from groupme), needed for all objects s = session.Session(KEYS.get_groupme_key()) # create the bot manager manager = bots.Bots(s) # stores the bot, assuming only 1 bot to keep track of, if more bots just add more # variables and increment the index try: BOT = manager.list()[0] except BaseException: while True: bot_name = KEYS.get_bot_name() group_name = KEYS.get_group_name() group_id = None for group in client.groups.list(): if group.name == group_name:
from groupy import Client import pickle client = Client.from_token('key') groups = list(client.groups.list_all()) for group in groups: if group.name == 'Cribb Floor 2': floor = group messages = [] for message in floor.messages.list_all(): try: print(message.text) messages.append(message.text) except UnicodeEncodeError: print('emoji encountered') pickle.dump(messages, open('messages.p', 'wb'))
import os from groupy import Client from termcolor import colored, cprint client = Client.from_token(input("Put your Acess Key here: ")) os.system('clear') groups = list(client.groups.list_all()) commands = ["/g" "/group" "/c" "/chat"] groups.reverse() for group in groups: cprint(group.name, 'cyan') groupnum = int(input("Which group would you like to read : ")) - 1 os.system('clear') messages = groups[groupnum].messages.list() message_list = [] for i in range(20): message_list.append(messages[i]) message_list.reverse() for message in message_list: print(colored(message.name + " : ", "cyan") + message.text) while True: message_text = input() for command in commands: if message_text == command: break
from groupy import Client from groupy import exceptions import time from LyricsBot import LyricsBot if __name__ == "__main__": access_token = "" bot_id = "" group_id = "" genius_token = "" client = Client.from_token(access_token) group = client.groups.get(group_id) messages = group.messages.list() lyricsBot = LyricsBot(bot_id, client, genius_token) messages = list(group.messages.list(limit=1)) message_id = messages[0].id while True: try: # If len of messages greater than 1, process messages, else do nothing if len(messages) >= 1: for message in messages: # Process message if message.text is not None: lyricsBot.check_message(message.text) # Get ID of most recent message message_id = messages[0].id # Get messages after message_id
from groupy import Client import os GROUP_ID = 48071223 client = Client.from_token(os.environ["GROUPME_ACCESS_TOKEN"]) group = client.groups.get(id=GROUP_ID) group.leave() while True: group.post(text=input("> "))
def client_obj(token): return Client.from_token(token)
def main(): # configure the argument options parser for the script parser = optparse.OptionParser(version="%prog 0.1") parser.add_option('--debug', action="store_true", dest="debug", help="debug output", default=False) parser.add_option('--token', type='string', dest="token", help="GroupMe developer access token") parser.add_option('--groupid', type="int", dest="id", help="GroupMe group ID to download media from") options, args = parser.parse_args() if options.debug == True: logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.INFO) # parse groupme developer access token if options.token: groupme_token = options.token else: groupme_token = credentials['gm_access_token'] # parse groupme group id if options.id: groupid = options.id else: groupid = credentials['gm_group_id'] logging.info('Started') # configure client for groupy (groupme) client = Client.from_token(groupme_token) # select the specific group if groupid: try: group = find_group(client, groupid) logging.info('Group selected (%s)' % groupid) except: logging.error('Unable to find group (%d)' % groupid) # if no group specified, create interactive list else: groups = list(client.groups.list_all()) # retrieve attachment data from the group retrieved_attachments = [] retrieved_attachments = retrieve_attachments(client, group) # create a subdirectory if not os.path.exists('dl'): os.mkdir('dl') logging.info("Starting download of all attachments...") # format the filenames of the attachments and proceed to downloading for attachment in retrieved_attachments: jpeg_ext = attachment['url'].rfind('.jpeg.') # check for .jpeg png_ext = attachment['url'].rfind('.png.') # check for .png backslash = attachment['url'].rfind('/') # find last backslash # JPEG extension if jpeg_ext != -1: file_hash = attachment['url'][jpeg_ext + 6:] filename = file_hash + '.' + attachment['url'][backslash + 1:jpeg_ext + 5] # PNG extension elif png_ext != -1: file_hash = attachment['url'][png_ext + 5:] filename = file_hash + '.' + attachment['url'][backslash + 1:png_ext + 4] # all others else: filename = attachment['url'][backslash + 1:] try: logging.info('Downloading: %s' % attachment['url']) with open('dl/' + filename, 'wb') as f: f.write(urllib.request.urlopen(attachment['url']).read()) f.close() logging.info('Saved to: %s' % filename) except: logging.error('Unable to download: %s' % attachment['url'])