Commit 635ee025 authored by A. Wilcox's avatar A. Wilcox 🦊
Browse files

lol I have no idea how to use asyncio

parent 2ff450f2
from configparser import ConfigParser
from os.path import expanduser
config = ConfigParser()['emily.cfg', expanduser('~/emily.cfg')])
\ No newline at end of file
"""The core of Emily."""
import asyncio
in_plugins = []
in_protocols = set()
in_proto_insts = []
out_plugins = []
event_loop = asyncio.get_event_loop()
def register_in(plugin):
for protocol in plugin.PROTOCOLS:
def register_out(plugin):
def run():
for proto in in_protocols:
from emily.protocols import http
import json
class GitLab:
""" Processes information from GitLab Web Hooks. """
PROTOCOLS = (http,)
def __init__(self):
def http_can_handle(headers, body):
return 'X-Gitlab-Event' in headers
def http_handle(headers, body):
from collections import defaultdict
from PyIRC.extensions import bot_recommended
from import IRCProtocol
from PyIRC.signal import event
from emily import config
class IRCNetwork(IRCProtocol):
"""The basic IRC network representation. Each network has an instance."""
def __init__(self, *args, **kwargs):
super(IRCNetwork, self).__init__(*args, **kwargs)
@event('commands', 'NOTICE')
def on_message(self, caller, line):
if line.params[0] == self.nick and line.params[-1].upper() == 'REHASH':
class IRC:
"""The IRC output plugin.
networks = comma separated list of networks. For each network:
network_server = IP or hostname
network_port = IRC port
network_ssl = True/False
network_nick = Nickname to use
network_gecos = GECOS
network_username = Username to auth with (or not present)
network_password = Password to auth with (or not present)
network_channels = comma separated list of channels. For each:
network_channel_projects = comma separated list of projects.
def __init__(self, loop):
myconf = config['irc']
self.networks = [network.strip()
for network in myconf['networks'].split(',')]
self.network_instances = {}
self.projects = defaultdict(list)
for network in self.networks:
args = {
'serverport': (myconf[network + '_server'],
int(myconf[network + '_port'])),
'ssl': myconf[network + '_ssl'].lower() == 'true',
'nick': myconf[network + '_nick'],
'gecos': myconf[network + '_gecos'],
'extensions': bot_recommended,
'join': [],
args['username'] = myconf.get(network + '_username',
myconf[network + '_nick'])
if network + '_username' in myconf:
args['sasl_username'] = myconf[network + '_username']
args['sasl_password'] = myconf[network + '_password']
for channel in [ch.strip()
for ch in myconf[network + '_channels'].split(',')]:
args['join'].append('#' + channel)
proj_setting = network + '_' + channel + '_projects'
for project in [proj.strip()
for proj in myconf[proj_setting]]:
'#' + channel))
netinst = IRCNetwork(**args)
self.network_instances[network] = netinst
coro = netinst.connect()
def push(self, project, push):
\ No newline at end of file
"""Basic protocol handling for Emily."""
from emily.protocols.http import HTTPProtocol as http
\ No newline at end of file
from aiohttp import web
from emily import config
class HTTPProtocol():
def __init__(self, loop):
if 'http' not in config:
config['http'] = {'port': 8085, 'ssl': False}
if config['http'].get('ssl', False):
# handle SSL
# listen on port = web.Application(loop=loop)'GET', '/{project}', self.get_handler)'POST', '/{project}', self.post_handler)'GET', '/{grp}/{project}', self.get_handler)'POST', '/{grp}/{project}', self.post_handler)
self.server = loop.create_server(,
'', int(config['http']['port']))
def get_handler(self, request):
"""Handle GET."""
def post_handler(self, request):
"""Handle POST."""
from emily.inp.gitlab import GitLab
from emily.out.irc import IRC
import emily.core
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment