Esempio n. 1
0
async def after_login_info():
    log.info('Connected servers: {}'.format(len(bot.servers)))

    update_server_count(bot.user.id, len(bot.servers))

    db.purge_table('connected_servers')
    table = db.table('connected_servers')
    for server in bot.servers:
        try:
            table.insert({
                'server': {
                    'id': server.id,
                    'name': server.name,
                    'owner': server.owner.id,
                    'member_count': server.member_count
                }
            })
        except:
            pass

    if config['updated']:
        for server in bot.servers:
            try:
                main_channel = [
                    c for c in list(server.channels)
                    if c.type == discord.ChannelType.text and c.position == 0
                ][0]
                await send_after_update_message(bot, main_channel)
            except:
                pass
Esempio n. 2
0
def create_command(bot):

    table = db.table('insults')

    @bot.command(pass_context=True, brief="Adds a new insult to the database.")
    async def addinsult(ctx, *, insult):
        """
        Adds a new insult to the database. Occurences of {} will be replaced
        with username, so you can have personalized insults.

        Example of use: !addinsult {} loves Oblivion
        """
        if '{}' not in insult:
            await bot.say('Your insult does not include "{}", rejected.')
        else:
            table.insert({'insult': insult})
            await bot.say('Insult added.')

    return addinsult
Esempio n. 3
0
def create_command(bot):

    table = db.table('insults')

    @bot.command(pass_context=True, brief="Insults another user")
    async def insult(ctx):
        """
        Insults another user.
        """
        if len(ctx.message.mentions) > 0:
            user = ctx.message.mentions[0]
            insults = table.all()
            if len(insults) < 1:
                await bot.say('No insults in the database.')
                return

            insult = random.choice(insults)['insult']

            await bot.say(insult.format(user.mention))
        else:
            await bot.say('Mention the user you want to insult.')

    return insult
Esempio n. 4
0
from discord import Colour, Embed
from discord.ext import commands as discord_commands

from checks import check_if_owner
from database import db

stats_table = db.table('stats')

def create_command(bot):
    @bot.command(pass_context=True, brief="Shows command statistics (owners only)")
    @discord_commands.check(check_if_owner)
    async def stats(ctx):
        embed = Embed()
        embed.type="rich"
        embed.title = 'Command invocation stats'
        
        embed.description = '```'

        rows = reversed(sorted(stats_table.all(), key=lambda x: x['invoked']))
        for row in rows:
            embed.description += '{}: {}\n'.format(row['name'], row['invoked'])

        embed.description += '```'
        
        await bot.say(None, embed=embed)
Esempio n. 5
0
def prefix(bot, msg):
    try:
        p = msg.content[0]
        if p == '!' or p == '.':
            return p
        else:
            return '!'
    except:
        return '!'


bot = discord_commands.Bot(command_prefix=prefix,
                           description=config['description'],
                           pm_help=True)
bot.command_functions = []
userdata = db.table('userdata')
stats = db.table('stats')


def startup_info():
    log.info('Starting Icarus...')
    if not config['dev']:
        periodic_autoupdate()


async def after_login_info():
    log.info('Connected servers: {}'.format(len(bot.servers)))

    update_server_count(bot.user.id, len(bot.servers))

    db.purge_table('connected_servers')
Esempio n. 6
0
import html
import json
import random
import requests

from database import db
from discord import Colour, Embed
from tinydb import Query


QUIZ_API = "https://opentdb.com/api.php?amount=1"
userdata = db.table('userdata')


def difficulty_to_stars(difficulty):
    if difficulty == 'easy':
        return ':star:'
    elif difficulty == 'medium':
        return ':star:'*2
    elif difficulty == 'hard':
        return ':star:'*3
    else:
        return 'Unknown'

def format_answers(correct, incorrect):
    answers = []
    answers.extend(incorrect)
    answers.append(correct)
    random.shuffle(answers)
    answers = list(enumerate(answers))