Ejemplo n.º 1
0
"""Base module."""
import os
import discord
import socket
import sys

import gearbox
cog = gearbox.Cog(config='yaml')
_ = cog.gettext
ngettext = cog.ngettext


@cog.command(permissions='manage_server')
def enable(__cogs, server_ex, *cogs: 'Name of cogs to enable'):
    """Enable cogs for the current server.

    If called with no cogs, displays enabled cogs. Use `*` to enable all cogs."""
    if not cogs:
        return _('Enabled cogs: {enabled_cogs}').format(
            enabled_cogs=gearbox.pretty(
                [c for c in __cogs.COGS if server_ex.is_allowed(c)],
                '`%s`',
                final=_('and')))
    if cogs == ('*', ):
        cogs = server_ex.blacklist[::]
        if not cogs:
            return _('No cogs are disabled.')
    not_found = [c for c in cogs if c not in __cogs.COGS]
    if not_found:
        return ngettext("{cogs_not_found} doesn't exist", "{cogs_not_found} don't exist", len(not_found))\
            .format(cogs_not_found=gearbox.pretty(not_found, '`%s`', final=_('and')))
Ejemplo n.º 2
0
"""Youtube feed notifier."""
import json
import arrow
import gearbox
cog = gearbox.Cog()


LANG = 'en_US'
ZONE = 'Europe/Paris'
_ = lambda s: s


@cog.on_socket(b'hook/youtube/')
async def publish_video(client, data_str, socket):
    data = json.loads(data_str)
    for video in data['items']:
        author = video['actor']['displayName']
        short_url = 'http://youtu.be/' + video['id'].split(':', 2)[2]
        published = arrow.get(video['published'])
        message = _('New video from **{author}**: {short_url} {time_ago} ({time})').format(
            author=author, short_url=short_url, time_ago=published.humanize(locale=LANG),
            time=published.to(ZONE).format(_('HH:mm'))
        )
        await client.send_message(client.get_channel('272463984026976257'), message)
Ejemplo n.º 3
0
"""Feed notifier cogs."""
import gearbox
cog = gearbox.Cog(config='json')
_ = cog.gettext


KEY_MAIN_CHAN = 'feed.main_channel'


@cog.command(permissions='manage_channels')
def setchannel(server_ex, server, channel_name=None):
    if channel_name is None:
        channel_id = server_ex.config.get(KEY_MAIN_CHAN)
        if channel_id is None:
            return _('No notification channel specified for this server, {general} will be used').format(
                general=server.default_channel.mention)
        else:
            return _('The main notification channel for this server is {channel}').format(channel='<#%s>' % channel_id)
    channel = gearbox.str_to_chan(server, channel_name)
    if not channel:
        return _('Unknown channel, try using #channel')
    server_ex.config[KEY_MAIN_CHAN] = channel.id
    server_ex.write()
    return _('The main notification channel for this server has been set to {channel}').format(channel=channel.mention)


@cog.command(permissions='manage_channels')
def unsetchannel(server_ex, server):
    if KEY_MAIN_CHAN in server_ex.config:
        server_ex.config.pop(KEY_MAIN_CHAN)
        server_ex.write()