コード例 #1
0
ファイル: draft.py プロジェクト: YuniQ152/PUBobot2
    async def pick(self, author, player):
        pick_step = max(0, (len(self.m.teams[0]) + len(self.m.teams[1]) - 2))
        picker_team = self.m.teams[self.pick_order[
            pick_step]] if pick_step < len(self.pick_order) - 1 else None

        if self.m.state != self.m.DRAFT:
            raise bot.Exc.MatchStateError(
                self.m.gt("The match is not on the draft stage."))
        elif (team := find(lambda t: author in t[:1],
                           self.m.teams[:2])) is None:
            raise bot.Exc.PermissionError(self.m.gt("You are not a captain."))
コード例 #2
0
    async def report_win(self, team_name):  # version for admins/mods
        if self.state != self.WAITING_REPORT:
            raise bot.Exc.MatchStateError(
                self.gt("The match must be on the waiting report stage."))

        team_name = team_name.lower()
        if team_name == "draw":
            self.winner = None
        elif (team := find(lambda t: t.name.lower() == team_name,
                           self.teams[:2])) is not None:
            self.winner = team.idx
コード例 #3
0
def find(args):
    """
    Function for finding all examples in a directory containing labels for given classes
    :param args:
    :return:
    """
    print("Finding all files labeled with classes" + args.classes + " in " + args.audio_data_dir)

    for class_name in args.classes:
        utils.find(class_name, args)
        print("Finished finding and sorting files for class: " + class_name)
コード例 #4
0
ファイル: draft.py プロジェクト: YuniQ152/PUBobot2
 async def cap_for(self, author, team_name):
     if self.m.state != self.m.DRAFT:
         raise bot.Exc.MatchStateError(
             self.m.gt("The match is not on the draft stage."))
     elif self.captains_role_id and self.captains_role_id not in (
             r.id for r in author.roles):
         raise bot.Exc.PermissionError(
             self.m.gt("You must possess the captain's role."))
     elif (team := find(lambda t: t.name.lower() == team_name.lower(),
                        self.m.teams[:2])) is None:
         raise bot.Exc.SyntaxError(
             self.m.gt("Specified team name not found."))
コード例 #5
0
ファイル: draft.py プロジェクト: YuniQ152/PUBobot2
class Draft:

    pick_steps = {"a": 0, "b": 1}

    def __init__(self, match, pick_order, captains_role_id):
        self.m = match
        self.pick_order = [self.pick_steps[i]
                           for i in pick_order] if pick_order else []
        self.captains_role_id = captains_role_id
        self.sub_queue = []

        if self.m.cfg['pick_teams'] == "draft":
            self.m.states.append(self.m.DRAFT)

    async def start(self):
        await self.refresh()

    async def print(self):
        try:
            await self.m.send(embed=self.m.embeds.draft())
        except DiscordException:
            pass

    async def refresh(self):
        if self.m.state != self.m.DRAFT:
            await self.print()
        elif len(self.m.teams[2]) and any(
            (len(t) < self.m.cfg['team_size'] for t in self.m.teams)):
            await self.print()
        else:
            await self.m.next_state()

    async def cap_for(self, author, team_name):
        if self.m.state != self.m.DRAFT:
            raise bot.Exc.MatchStateError(
                self.m.gt("The match is not on the draft stage."))
        elif self.captains_role_id and self.captains_role_id not in (
                r.id for r in author.roles):
            raise bot.Exc.PermissionError(
                self.m.gt("You must possess the captain's role."))
        elif (team := find(lambda t: t.name.lower() == team_name.lower(),
                           self.m.teams[:2])) is None:
            raise bot.Exc.SyntaxError(
                self.m.gt("Specified team name not found."))

        if len(team):
            # raise bot.Exc.PermissionError(self.m.gt("Team {name} already have a captain.".format(name=f"**{team.name}**")))
            self.m.teams[2].append(team.pop(0))

        find(lambda t: author in t, self.m.teams).remove(author)
        team.insert(0, author)
        await self.print()
コード例 #6
0
ファイル: rating.py プロジェクト: YuniQ152/PUBobot2
 async def get_players(self, user_ids):
     """ Return rating or initial rating for each member """
     data = await db.select([
         'user_id', 'rating', 'deviation', 'channel_id', 'wins', 'losses',
         'draws'
     ],
                            self.table,
                            where={'channel_id': self.channel_id})
     results = []
     for user_id in user_ids:
         if d := find(lambda p: p['user_id'] == user_id, data):
             if d['rating'] is None:
                 d['rating'] = self.init_rp
                 d['deviation'] = self.init_deviation
         else:
             d = dict(channel_id=self.channel_id,
                      user_id=user_id,
                      rating=self.init_rp,
                      deviation=self.init_deviation,
                      wins=0,
                      losses=0,
                      draws=0)
         results.append(d)
コード例 #7
0
ファイル: draft.py プロジェクト: YuniQ152/PUBobot2
    async def sub_for(self, player1, player2, force=False):
        if self.m.state not in [self.m.DRAFT, self.m.WAITING_REPORT]:
            raise bot.Exc.MatchStateError(
                self.m.gt(
                    "The match must be on the draft or waiting report stage."))
        elif not force and player1 not in self.sub_queue:
            raise bot.Exc.PermissionError(
                self.m.gt("Specified player is not looking for a substitute."))

        team = find(lambda t: player1 in t, self.m.teams)
        team[team.index(player1)] = player2
        self.m.players.remove(player1)
        self.m.players.append(player2)
        if player1 in self.sub_queue:
            self.sub_queue.remove(player1)
        self.m.ratings = {
            p['user_id']: p['rating']
            for p in await self.m.qc.rating.get_players((
                p.id for p in self.m.players))
        }
        await self.m.qc.remove_members(player2)
        await bot.remove_players(player2, reason="pickup started")
        await self.print()
コード例 #8
0
    async def report_loss(self, member, draw):
        if self.state != self.WAITING_REPORT:
            raise bot.Exc.MatchStateError(
                self.gt("The match must be on the waiting report stage."))

        team = find(lambda team: member in team[:1], self.teams[:2])
        if team is None:
            raise bot.Exc.PermissionError(
                self.gt(
                    "You must be a team captain to report a loss or draw."))

        enemy_team = self.teams[1 - team.idx]
        if draw and not enemy_team.want_draw:
            team.want_draw = True
            await self.qc.channel.send(
                self.
                gt("{self} is calling a draw, waiting for {enemy} to type `{prefix}rd`."
                   ).format(self=member.mention,
                            enemy=enemy_team[0].mention,
                            prefix=self.qc.cfg.prefix))
            return

        self.winner = None if draw else enemy_team.idx
        await self.finish_match()
コード例 #9
0
ファイル: geomappers.py プロジェクト: xXxRisingTidexXx/raions
 def _get_locality(self, location: Dict[str, Any]) -> Optional[str]:
     address = location['address']
     return find(
         lambda l: not (l is None or l.endswith(' рада') or l.endswith(
             ' район')),
         (address.get('city'), address.get('town'), address.get('village')))
コード例 #10
0
ファイル: test_utils.py プロジェクト: xXxRisingTidexXx/raions
def test_find_errors():
    with raises(AttributeError):
        find(lambda w: w.endswith('sid'),
             ['Boobs', 'T**s', 'Dick', 'Pussy', 'Vgine', {
                 'a': 4
             }, 'Abbaside'])
コード例 #11
0
ファイル: test_utils.py プロジェクト: xXxRisingTidexXx/raions
def test_find_nothing(predicate: Callable):
    assert find(predicate, [
        'Oh my Zsh', 'F****n shit', 'Shirts', 'T-shirt', 'Oh, my',
        'KS strangers'
    ]) is None
コード例 #12
0
ファイル: test_utils.py プロジェクト: xXxRisingTidexXx/raions
def test_find_something(predicate: Callable, expected: str):
    assert expected == find(predicate, [
        'Cassandra', 'Bad Liar', 'S3', 'New-Old-Bad-Day', 'Ich Will',
        'Моя мила', 'Пирамидаль', 'A-b-y-s-s', 'NeXus', 'Моя боротьба',
        'xustain', '911'
    ])
コード例 #13
0
ファイル: draft.py プロジェクト: YuniQ152/PUBobot2
 async def put(self, player, team_name):
     if (team := find(lambda t: t.name.lower() == team_name.lower(),
                      self.m.teams)) is None:
         raise bot.Exc.SyntaxError(
             self.m.gt("Specified team name not found."))
コード例 #14
0
ファイル: draft.py プロジェクト: YuniQ152/PUBobot2
                picker_team.extend(self.m.teams[2])
                self.m.teams[2].clear()

        await self.refresh()

    async def put(self, player, team_name):
        if (team := find(lambda t: t.name.lower() == team_name.lower(),
                         self.m.teams)) is None:
            raise bot.Exc.SyntaxError(
                self.m.gt("Specified team name not found."))
        if self.m.state not in [self.m.DRAFT, self.m.WAITING_REPORT]:
            raise bot.Exc.MatchStateError(
                self.m.gt(
                    "The match must be on the draft or waiting report stage."))

        find(lambda t: player in t, self.m.teams).remove(player)
        team.append(player)
        await self.refresh()

    async def sub_me(self, author):
        if self.m.state not in [self.m.DRAFT, self.m.WAITING_REPORT]:
            raise bot.Exc.MatchStateError(
                self.m.gt(
                    "The match must be on the draft or waiting report stage."))

        if author in self.sub_queue:
            self.sub_queue.remove(author)
            await self.m.qc.success(
                self.m.gt("You have stopped looking for a substitute."))
        else:
            self.sub_queue.append(author)