def main(argv): # Slack config: "HOOK_URL1,HOOK_URL2,HOOK_URL3,..." slack_config = os.environ.get('CUPY_CI_SLACK_CONFIG', None) # Gitter config: "TOKEN:ROOM1,ROOM2,ROOM3,..." gitter_config = os.environ.get('CUPY_CI_GITTER_CONFIG', None) subdesc = os.environ.get('FLEXCI_SUB_DESCRIPTION', '') if subdesc == '': subdesc = os.environ.get('FLEXCI_DESCRIPTION', '(no description)') url = os.environ.get('FLEXCI_JOB_URL', '<no url>') msg = argv[1] body = '''\ *{}:* {} ``` {} ``` '''.format(msg, url, subdesc) if slack_config is not None: from slack_sdk.webhook import WebhookClient for hook_url in slack_config.split(','): slack = WebhookClient(hook_url) slack.send(text=body) if gitter_config is not None: from gitterpy.client import GitterClient token, rooms = gitter_config.split(':') gitter = GitterClient(token) for room in rooms.split(','): gitter.messages.send(room, body)
def display_messages(self) -> None: self.gitter = GitterClient(TOKEN) self.channel = CHANNEL self.messages = self.get_messages() self.messages_buff = len(self.messages) * [None] # color_data = [] # data = [] # for i in range(len(messages) - 1, -1, -1): # # replace empty char # messages[i].message = messages[i].message.replace(chr(8203), '') # data.append(messages[i].name + " " + messages[i].message) # color_data.append(messages[i].color) # self.entry_widget.highlighting_arr_color_data = color_data self.values = [m.text for m in self.get_messages()] if len(self.messages) > self.height - 3: self.entry_widget.start_display_at = len( self.messages) - self.height + 3 else: self.entry_widget.start_display_at = 0 self.entry_widget.cursor_line = len(self.messages) self.name = self.channel # self.footer = client.online[current_user] # the value that self.display()
def __init__(self, token, room_address, actions): self.gitter_client = GitterClient(token=token) self.room = room_address self.actions = actions start_listening_for_events(self) for event in self.room_updates(): for action in actions: if action.is_triggered_by(event): action.run(event, self)
def gitter(): from gitterpy.client import GitterClient # Once create instance gitter = GitterClient(settings.GITTER_TOKEN) # Check_my id val = gitter.rooms.grab_room('gitcoinco/Lobby')['userCount'] Stat.objects.create( key='gitter_users', val=val, )
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Gitter sensor.""" name = config.get(CONF_NAME) api_key = config.get(CONF_API_KEY) room = config.get(CONF_ROOM) gitter = GitterClient(api_key) try: username = gitter.auth.get_my_id["name"] except GitterTokenError: _LOGGER.error("Token is not valid") return add_entities([GitterSensor(gitter, room, name, username)], True)
def setup_platform( hass: HomeAssistant, config: ConfigType, add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the Gitter sensor.""" name = config.get(CONF_NAME) api_key = config.get(CONF_API_KEY) room = config.get(CONF_ROOM) gitter = GitterClient(api_key) try: username = gitter.auth.get_my_id["name"] except GitterTokenError: _LOGGER.error("Token is not valid") return add_entities([GitterSensor(gitter, room, name, username)], True)
def get_all_messages(gitter_token="", chat="tiny-dnn/developers", out_path='messages.json'): gitter = GitterClient(gitter_token) gitter.rooms.join(chat) messages = [] ret = gitter.messages.list(chat) messages += ret while len(ret) != 0: before_id = messages[0]['id'] BaseApi.footers = "?limit=100&beforeId=%s" % str(before_id) try: ret = gitter.messages.list(chat) except: break messages = ret + messages if len(ret) > 0: print(ret[0]) with open(out_path, 'w') as output: json.dump(messages, output)
'chatterbot.preprocessors.clean_whitespace', ], logic_adapters=[ 'chatterbot.logic.MathematicalEvaluation', 'chatterbot.logic.TimeLogicAdapter', 'chatterbot.logic.BestMatch' ]) # Run this once to generate good stuff for database to start with # Warning takes 6 hours approximately to run #trainer = UbuntuCorpusTrainer(chatbot) #trainer.train() gitter_api_token = 'YOUR-API-TOKEN' # Gitter API token gitter_room = 'YOUR-ROOM/YOUR-SUB-ROOM' # Gitter Room Name gitter = GitterClient(gitter_api_token) while True: try: response = gitter.stream.chat_messages(gitter_room) for stream_messages in response.iter_lines(): if is_json(stream_messages): resp = json.loads(stream_messages) if 'msg' in globals(): if resp['text'] == msg: continue if 'botresp' in globals(): if str(botresp) == msg: continue msg = resp['text'] userid = resp['fromUser']['username'] if userid == gitter.auth.get_my_id['name']:
#CONFS room_name = 'nem0/LumixEngine' # room_name = 'gitterHQ/sandbox' # room_name = 'AtomicGameEngine/AtomicGameEngine' from gitterpy.client import GitterClient from asteval.asteval import Interpreter from json import loads aeval = Interpreter() gitter = GitterClient(open("token.txt").readline()) users = [x.rstrip() for x in open("users.txt").readlines()] aeval("users = " + str(users)) last_message = ":trollface:" # TESTING # def say2(msg): # print(str(msg)) # while True: # message = {'text':input("> "),'fromUser':{"username":"******"}} # try: # text = message['text'] # if "$LAST" in text: # text = text.replace("$LAT", "'"+last_message+"'") # last_message = text # user = message['fromUser']['username'] # command = text.split(' ')[0] # if command == 'eval': # args = ' '.join(text.split(' ')[1:]) # eval_result = aeval(args) # if eval_result is not None:
def __init__(self, token, community): self.community = community self.client = GitterClient(token)
#!/usr/bin/env python # Why this script? See https://phabricator.wikimedia.org/T104799 from __future__ import print_function import requests import subprocess import sys from datetime import datetime from gitterpy.client import GitterClient # Once create instance gitter = GitterClient('bf8951be6f67edb1b4536595b442453e07e7e899') def restart_server(): subprocess.call(['/usr/local/bin/webservice', 'restart']) try: res = requests.get('https://croptool.toolforge.org/server-statistics', timeout=10) except requests.exceptions.Timeout: print('Timeout when checking server-statistics. Restarting') gitter.messages.send( 'croptool/Lobby', 'Timeout when checking server-statistics. @danmichaelo') # restart_server() sys.exit(0) res.text.split('\n') items = [line.split(': ') for line in res.text.split('\n')]
from gitterpy.client import GitterClient configfile: "config.yaml" # connect to Gitter API gitter = GitterClient(config["token"]["gitter"]) for message in gitter.messages.list("Galaxy Training Network/Lobby"): print(message["sent"])