def handle_alliance(self, msg, chat_handler):
        if (yield from assert_text(msg, chat_handler)):
            alliance_name = msg["text"]

            GroupLink.create_or_get(group=self._group,
                                    character_field_name="alliance_name",
                                    field_value=alliance_name)
            self.finished()
            yield from chat_handler.sender.sendMessage(
                _s["msg_linkadded"], reply_markup={'hide_keyboard': True})
Exemple #2
0
    def handle_corp(self, msg, chat_handler):
        if (yield from assert_text(msg,chat_handler)):
            corp_name = msg["text"]

            GroupLink.create_or_get(
                group=self._group,
                character_field_name="corporation_name",
                field_value=corp_name
            )
            self.finished()
            yield from chat_handler.sender.sendMessage(_s["msg_linkadded"],reply_markup={'hide_keyboard': True})
Exemple #3
0
async def auto_group_char(user, character):
    try:
        player_name = user.display_name()

        # find all group links for this character
        char_links = [
            set(link.group.group_name for link in GroupLink.select().where(
                GroupLink.character_field_name == field_name,
                GroupLink.field_value == getattr(character, field_name)))
            for field_name in Character._meta.fields.keys()
        ]

        flat_links = set.union(*char_links)

        for linked_group_name in flat_links:

            linked_group = Group.select().where(
                Group.group_name == linked_group_name).get()

            add = True
            link_fields = {
                link.character_field_name: False
                for link in GroupLink.select().where(
                    GroupLink.group == linked_group)
            }

            # make sure this character satisfies every link for this group
            for link in GroupLink.select().where(
                    GroupLink.group == linked_group):
                if getattr(character,
                           link.character_field_name) == link.field_value:
                    link_fields[link.character_field_name] = True
            for lf in link_fields:
                add = add and link_fields[lf]

            approved = linked_group.auto_approval
            if len(GroupApproval.select().where(
                    GroupApproval.user == user, GroupApproval.group
                    == linked_group)) > 0:
                approved = True

            if add and approved:
                GroupMembership.create_or_get(user=user, group=linked_group)
                logging.warning("Added " + player_name + " to " +
                                linked_group.group_name)

    except:
        traceback.print_exc()
async def auto_group_char(user, character):
    try:
        player_name = user.display_name()

        # find all group links for this character
        char_links = [
            set(link.group.group_name for link in GroupLink.select().where(
                GroupLink.character_field_name == field_name,
                GroupLink.field_value == getattr(character, field_name))
                )
            for field_name in Character._meta.fields.keys()
            ]

        flat_links = set.union(*char_links)

        for linked_group_name in flat_links:

            linked_group = Group.select().where(Group.group_name == linked_group_name).get()

            add = True
            link_fields = {link.character_field_name: False for link in
                           GroupLink.select().where(GroupLink.group == linked_group)}

            # make sure this character satisfies every link for this group
            for link in GroupLink.select().where(GroupLink.group == linked_group):
                if getattr(character, link.character_field_name) == link.field_value:
                    link_fields[link.character_field_name] = True
            for lf in link_fields:
                add = add and link_fields[lf]

            approved = linked_group.auto_approval
            if len(GroupApproval.select().where(
                            GroupApproval.user == user,
                            GroupApproval.group == linked_group)) > 0:
                approved = True

            if add and approved:
                GroupMembership.create_or_get(
                    user=user,
                    group=linked_group
                )
                logging.warning("Added " + player_name + " to " + linked_group.group_name)

    except:
        traceback.print_exc()