Exemplo n.º 1
0
async def get_step(ctx, user: discord.Member = None):
    if user is None:
        user_id = ctx.author.id
    else:
        if not await utils.is_admin(ctx):
            return
        user_id = user.id

    step = bank.get_income_step(user_id)
    if user is not None:
        dm = await ctx.author.create_dm()

        if step is None:
            res = "Erreur : {} n'a pas de compte en banque.".format(utils.mention(user_id))
            log_error(res)
        else:
            res = "{} est au palier {} et a donc un revenu de {}ŧ.".format(utils.mention(user_id), step, INCOME_BASE + step * INCOME_STEP_VALUE)
            log_info(res)

        await dm.send(res)
    else:
        if step is None:
            res = "Erreur : vous n'avez pas de compte en banque. Pour le créer : `.new_account`"
            log_error(res)
        else:
            res = "Vous êtes au palier {} et avez donc un revenu de {}ŧ .".format(step, INCOME_BASE + step*INCOME_STEP_VALUE)
            log_info(res)

        await ctx.send(res)
Exemplo n.º 2
0
async def pay_salaries(ctx):
    from_id = ctx.author.id
    ret_values = bank.pay_all_salaries(from_id)

    res = []
    paid = []
    error = []
    for user_id, v, salary in ret_values:
        if v == 1:
            error.append("Erreur : Le compte débiteur ({}) n'existe pas.".format(utils.mention(from_id)))
            log_error(res[-1])
            break

        if v == 0:
            res.append("Son salaire a été versé à {}.\n".format(await get_name(user_id)))
            paid.append((user_id, salary))
            log_info(res[-1])
        elif v == 2:
            error.append("Erreur : La salaire de {} est nul.".format(await get_name(user_id)))
            log_error(res[-1])
        elif v == 3:
            error.append("Erreur : Le débiteur ({}) n'a plus les fonds nécéssaires.".format(utils.mention(from_id)))
            res.append(error[-1][1])
            log_error(res[-1])
            break

    for user_id, amount in paid:
        user = await client.fetch_user(user_id)
        dm = await user.create_dm()
        await dm.send("Vous avez reçu votre salaire de {}ŧ.".format(amount/100))

    await utils.send_msg(error + res, ctx)
Exemplo n.º 3
0
async def get_salary(ctx, user: discord.Member = None):
    if user is None:
        user_id = ctx.author.id
    else:
        if not await utils.is_admin(ctx):
            return
        user_id = user.id

    salary = bank.get_salary(user_id)
    if user is not None:
        dm = await ctx.author.create_dm()

        if salary is None:
            res = "Erreur : {} n'a aucun de métier.".format(utils.mention(user_id))
            log_error(res)
        else:
            res = "{} a un salaire mensuel de {} pour l'ensemble de ses métiers.".format(utils.mention(user_id), salary/100)
            log_info(res)

        await dm.send(res)
    else:
        if salary is None:
            res = "Erreur : vous n'avez pas de métier."
            log_error(res)
        else:
            res = "Vous avez un salaire mensuel de {}ŧ pour l'ensemble de vos métiers.".format(salary/100)
            log_info(res)

        await ctx.send(res)
 def analyse_message(
     message: MessageLog,
     mentions: Dict[str, Counter],
     raw_members: List[int],
     *,
     all_mentions: bool,
 ) -> bool:
     impacted = True
     if not message.bot or all_mentions:
         for member_id in message.mentions:
             if member_id in raw_members:
                 count = message.content.count(
                     mention(member_id)) + message.content.count(
                         alt_mention(member_id))
                 mentions[mention(message.author)].update_use(
                     count, message.created_at)
     return impacted
Exemplo n.º 5
0
async def setcode(ctx: Context, join_code: str):
    if not valid_join_code(join_code):
        await ctx.send(f'{join_code} is not a valid join code!')
        return

    game_id = await game_storage.set_code(ctx.author.id, join_code)
    signed_ids = await game_storage.get_signed_for_game(game_id)
    mentions = ' '.join(mention(user_id) for user_id in signed_ids)
    await ctx.send(f'New join code for game {game_id}: {join_code} {mentions}')
Exemplo n.º 6
0
async def del_job(ctx, user: discord.Member, job_id: int):
    """
    Remove a given job for a given user with:

    .del_job <user_id> <job_id>
    """
    user_id = user.id

    job = jobs_mgr.remove_job(user_id, job_id)
    if job is None:
        res = "Erreur : Le métier pour le.a citoyen.ne ({}) ayant pour identifiant {} n'existe pas".format(
            utils.mention(user_id), job_id)
        log_error(res)
        return res

    res = "{} n'est plus {}.".format(utils.mention(user_id), job[2])
    log_info(res)
    await ctx.send(res)
Exemplo n.º 7
0
async def get_citizens(ctx):
    dm = await ctx.author.create_dm()
    citizens = bank.get_citizens()
    res = []
    if not citizens:
        await dm.send("La ville est déserte.")
        return

    res.append("Liste des citoyens de Fibreville :")
    for citizen in citizens:
        res.append("{} : {}".format(await get_name(citizen[0]), utils.mention(citizen[0])))
    await utils.send_msg(res, dm)
Exemplo n.º 8
0
async def start(ctx: Context, join_code: Optional[str] = None):
    if join_code is None:
        await ctx.send(
            'Could not start game because join code was not provided!')
        return

    elif not valid_join_code(join_code):
        await ctx.send(f'{join_code} is not a valid join code!')
        return

    game_id = await game_storage.start(ctx.author.id, join_code)
    signed_ids = await game_storage.get_signed_for_game(game_id)
    mentions = ' '.join(mention(user_id) for user_id in signed_ids)
    await ctx.send(
        f'Game {game_id} has started with join code: {join_code} {mentions}')
Exemplo n.º 9
0
 def get_results(self, intro: str) -> List[str]:
     names = [name for name in self.messages]
     names.sort(key=lambda name: self.messages[name].score(), reverse=True)
     names = names[:self.top]
     usage_count = Counter.total(self.messages)
     res = [intro]
     res += [
         self.messages[name].to_string(
             names.index(name),
             mention(name),
             total_usage=usage_count,
             counted="message",
             transform=lambda id: f" in {channel_mention(id)}",
         ) for name in names
     ]
     return res
Exemplo n.º 10
0
def cheat():
    args = parse_args(request)
    is_pvp = 'opponent' in args
    db = db_session()
    # check to make sure player is in a game
    curr_game = None
    if is_pvp:
        curr_game = check_in_pvp(args['uid'], args['opponent'], db)
    else:
        curr_game = check_in_game(args['uid'], db)
    if curr_game == None:
        return 'bruh ur not in a game rn' + mention(args)
    # return cheats
    board, eval, best = cheat_board(curr_game.moves)

    return board + '\n' + eval + '\n' + best + '\n' + 'that good enough for you? stupid cheater' + mention(
        args)
Exemplo n.º 11
0
def ff():
    args = parse_args(request)
    is_pvp = 'opponent' in args
    db = db_session()
    # check to make sure player is in a game
    curr_game = None
    if is_pvp:
        curr_game = check_in_pvp(args['uid'], args['opponent'], db)
    else:
        curr_game = check_in_game(args['uid'], db)
    if curr_game == None:
        return 'bruh ur not in a game rn' + mention(args)
    # resign the player and claim victory
    db.delete(curr_game)
    db.commit()
    if not is_pvp:
        return claim_victory(curr_game.moves, args)
    else:
        return pvp_claim_victory(curr_game.moves, args)
Exemplo n.º 12
0
async def sign(ctx: Context, game_id: Optional[int] = None):
    sender_id = ctx.author.id
    sender_mention = mention(sender_id)
    if game_id is None:
        last_id = await game_storage.get_last_id()
        if last_id is None:
            last_id = await game_storage.create_game(sender_id)
            await ctx.send(f'{sender_mention} hosted new game {last_id}.')

        game_id = last_id

    try:
        signed_count = await game_storage.sign(game_id, sender_id)

    except asyncpg.UniqueViolationError:
        await ctx.send(f'You have already signed for a game, {sender_mention}.'
                       )

    except GameNotFound:
        await ctx.send(
            f"{sender_mention} couldn't sign for game {game_id} because it doesn't exist or isn't active."
        )

    except GameFull:
        await ctx.send(
            f"{sender_mention} couldn't sign for game {game_id} because it is full."
        )

    except Exception as exc:
        await ctx.send(
            f"{sender_mention} couldn't sign for game {game_id} because of some unknown error."
        )
        raise exc

    else:
        await ctx.send(
            f'{sender_mention} successfully signed for game {game_id} ({signed_count}/10).'
        )
Exemplo n.º 13
0
 async def _send_reply(self, response):
     await self._send_response(utils.mention(self.author) + ' ' + response)