}
}
-feeds = []
-greetings = []
-orders = []
+def get_bot_variable(k, v = None):
+ bot = bots.get(str(client.user.id), [])
+ if k in bot:
+ return bot.get(k, v)
+ return v
def open_url(url):
if sys.version_info >= (3, 0):
@asyncio.coroutine
def greet(channel, member, sound = True):
- for greeting in greetings:
+ for greeting in get_bot_variable(greetings, []):
if greeting['channel'] != int(channel.id):
continue
message = ' '.join([member.mention, greeting['message']])
pass
@asyncio.coroutine
-def do_feeds(feeds):
+def do_feeds():
while True:
- for feed in feeds:
+ for feed in get_bot_variable('feeds', []):
yield from set_rss_permissions(feed)
yield from do_rss(feed)
yield from asyncio.sleep(rsstime.value)
pass
@asyncio.coroutine
-def do_orders(orders):
+def do_orders():
while True:
waittime = None
given = {}
now = time.time()
- for order in orders:
+ for order in get_bot_variable('orders', []):
if waittime is None or waittime > order['seconds']:
waittime = order['seconds']
digest = hashlib.sha224(order['message'].encode('utf-8')).hexdigest()
else:
yield from maybe_say(message.channel, 'meow!')
-@asyncio.coroutine
def channels_to_greet():
+ greetings = get_bot_variable('greetings', [])
+ if not len(greetings):
+ return []
channels = []
for channel in client.get_all_channels():
if channel.is_private:
@asyncio.coroutine
def on_ready():
log.info('Logged in as {}#{}'.format(client.user.name, client.user.id))
- bot = bots.get(str(client.user.id), [])
- if bot is not None:
- feeds = bot.get('feeds', [])
- greetings = bot.get('greetings', [])
- orders = bot.get('orders', [])
+ feeds = get_bot_variable('feeds', [])
+ orders = get_bot_variable('orders', [])
log.info('Admins are: {}'.format(admins))
yield from wake_up(True)
- channels = yield from channels_to_greet()
+ channels = channels_to_greet()
log.info('Greeting in {}'.format([channel.name for channel in channels]))
for channel in channels:
log.debug('Greeting in {}'.format(channel.name))
log.debug('Maybe unassigning {}'.format(member.name))
yield from set_unassigned(member)
log.info('RSS feeds: {}'.format([feed['description'] for feed in feeds if 'description' in feed]))
- asyncio.async(do_feeds(feeds))
+ asyncio.async(do_feeds())
log.info('Orders in {}'.format([channel.name for channel in filter(None, [client.get_channel(str(order['channel'])) for order in orders])]))
- asyncio.async(do_orders(orders))
+ asyncio.async(do_orders())
asyncio.async(maybe_sleep())
def mentioned_in(message, explicit = True):
@client.event
@asyncio.coroutine
def on_member_join(member):
- channels = yield from channels_to_greet()
+ channels = channels_to_greet()
for channel in channels:
result = should_greet_member_in(channel, member)
if result: