Exemple #1
0
 def insert_group_mention(self, chat_id, reply, mention, user_id):
     if reply:
         if mention == "o":
             insert = ["pm", "off"]
         elif mention == "m":
             insert = ["off", "admins"]
         else:
             group = self.db["groups"].find_one_and_update(
                 {"id": chat_id}, {"$addToSet": {
                     "pm": user_id
                 }}, {"_id": 0},
                 return_document=ReturnDocument.AFTER)
             return Group(**group)
     else:
         if mention == "o":
             insert = ["pm", "off"]
         else:
             insert = ["off", "pm"]
     group = self.db["groups"].find_one_and_update(
         {"id": chat_id}, {
             "$pull": {
                 insert[0]: user_id
             },
             "$addToSet": {
                 insert[1]: user_id
             }
         }, {"_id": 0},
         return_document=ReturnDocument.AFTER)
     return Group(**group)
Exemple #2
0
 def insert_group_reply(self, chat_id, reply):
     # if reply is false, it means reply is true. Since reply is actually the people from the former mention group
     if isinstance(reply, list):
         group = self.db["groups"].find_one_and_update(
             {"id": chat_id},
             {
                 "$set": {
                     "reply": False
                 },
                 "$addToSet": {
                     "pm": {
                         "$each": reply
                     }
                 }
             },
             {"_id": 0},
             return_document=ReturnDocument.AFTER,
         )
     else:
         group = self.db["groups"].find_one_and_update(
             {"id": chat_id},
             {"$set": {
                 "reply": True
             }},
             {"_id": 0},
             return_document=ReturnDocument.AFTER,
         )
     return Group(**group)
def registerGroup():
    form = RegisterFormGroup()
    if form.validate_on_submit():
        group = Group(name=form.name.data)
        if group.save():
            return redirect(url_for("users.group_management"))
    return render_template("register_group.html", form=form)
Exemple #4
0
def my_chat_member_update(update, _):

    if update.effective_chat.type not in ["group", "supergroup"]:
        # we only care if we were added or removed from a group
        return

    status_change = update.my_chat_member.difference().get("status")

    if status_change is None:
        return

    old_status, new_status = status_change

    if new_status in [
            ChatMember.LEFT,
            ChatMember.KICKED,
    ]:
        database.remove_group(update.effective_chat.id)
    elif new_status in [ChatMember.ADMINISTRATOR, ChatMember.MEMBER]:
        chat = update.effective_chat
        database.add_group(
            Group(
                chat.id,
                html.escape(chat.title),
                [x.user.id for x in chat.get_administrators()],
            ))
Exemple #5
0
 def remove_group_link(self, chat_id, to_link_id):
     group = self.db["groups"].find_one_and_update(
         {"id": chat_id},
         {"$pull": {
             "linked_groups": to_link_id
         }},
         {"_id": 0},
         return_document=ReturnDocument.AFTER,
     )
     group2 = self.db["groups"].find_one_and_update(
         {"id": to_link_id},
         {"$pull": {
             "linked_groups": chat_id
         }},
         {"_id": 0},
         return_document=ReturnDocument.AFTER,
     )
     return Group(**group), Group(**group2)
Exemple #6
0
    def __init__(self, scene):
        # Title
        self.text_y = 101
        self.text = "KAbaLYN"
        self.font = FontManager.load_font('blade.ttf', 72)

        # Buttons
        self.buttons = Group((ButtonPlay(scene), ButtonMultiplayer(scene),
                              ButtonOptions(scene), ButtonExit(scene)))
Exemple #7
0
    def __init__(self, scene):
        # Title
        self.text_y = 101
        self.text = LanguageManager.load_text("uiPause")
        self.font = FontManager.load_font('blade.ttf', 72)

        # Buttons
        self.buttons = Group(
            (ButtonContinue(scene), ButtonOptions(scene), ButtonQuit(scene)))
Exemple #8
0
def added(update, context):
    if context.bot.id not in [
            x.id for x in update.effective_message.new_chat_members
    ]:
        return
    update.effective_message.reply_text(strings.ADDED)
    chat = update.effective_chat
    database.add_group(
        Group(chat.id, chat.title,
              [x.user.id for x in chat.get_administrators()]))
Exemple #9
0
 def insert_group_administration(self, chat_id, value):
     group = self.db["groups"].find_one_and_update(
         {"id": chat_id},
         {"$set": {
             "administration": value
         }},
         {"_id": 0},
         return_document=ReturnDocument.AFTER,
     )
     return Group(**group)
Exemple #10
0
    def __init__(self, scene):
        # Title
        self.text_y = 101
        self.text = LanguageManager.load_text("uiOptions")
        self.font = FontManager.load_font('blade.ttf', 72)

        # Buttons
        self.buttons = Group(
            (ButtonLanguage(scene), ButtonMasterVolume(scene),
             ButtonSoundVolume(scene), ButtonMusicVolume(scene),
             ButtonCancel(scene), ButtonConfirm(scene)))
Exemple #11
0
    def __init__(self, entities, balls=[]):
        # Calculate sprite corners
        spr_corner = SpriteManager.load_sprite('spr_corner.png')

        width = spr_corner.get_width()
        height = spr_corner.get_height()

        spr_corner_top_left = swap_color(spr_corner, Colors.WHITE, Colors.GREY)
        spr_corner_top_right = pygame.transform.flip(spr_corner_top_left, True,
                                                     False)
        spr_corner_bottom_left = pygame.transform.flip(spr_corner_top_left,
                                                       False, True)
        spr_corner_bottom_right = pygame.transform.flip(
            spr_corner_top_right, False, True)

        # Generate sprite panel
        self.spr_panel = pygame.Surface((width * 2, height * 2))
        self.spr_panel.fill(Colors.BLACK)
        self.spr_panel.blit(spr_corner_top_left, (0, 0))
        self.spr_panel.blit(spr_corner_top_right, (width, 0))
        self.spr_panel.blit(spr_corner_bottom_left, (0, height))
        self.spr_panel.blit(spr_corner_bottom_right, (width, height))
        self.spr_panel.set_colorkey(Colors.BLACK)

        # Surface for objects that are going to have a shadow
        self.display = pygame.Surface((250, 350))

        # Entities group
        self.entities = Group(entities)

        # Projectiles group
        self.projectiles = Group()

        # Balls group
        self.balls = Group()
        for x, y, radius in balls:
            self.balls.add(Ball(x, y, radius))

        # Particles groups
        self.top_particles = Group()
        self.bottom_particles = Group()
Exemple #12
0
 def insert_group_report(self, chat_id, new_report):
     if new_report == "b":
         insert = [True, True]
     elif new_report == "a":
         insert = [True, False]
     else:
         insert = [False, True]
     group = self.db["groups"].find_one_and_update(
         {"id": chat_id},
         {"$set": {
             "admin": insert[0],
             "report": insert[1]
         }}, {"_id": 0},
         return_document=ReturnDocument.AFTER)
     return Group(**group)
Exemple #13
0
class SceneFade(Scene):
    is_fading = False
    function = None
    arguments = None
    executed = False
    counter = 0
    fades = Group()

    def fade(self, function, *args):
        SceneFade.is_fading = True
        SceneFade.function = function
        SceneFade.arguments = args
        SceneFade.executed = False
        Fade.reverse = False

    def pre_update(self, events):
        pass

    def update(self, delta_time):
        # Check is the scene is fading
        if SceneFade.is_fading:
            # Add fade animation
            if SceneFade.counter < 16:
                SceneFade.fades.add(Fade(SceneFade.counter))
                SceneFade.counter += 1

            # Check if the fade is over
            elif len(SceneFade.fades) == 0:
                SceneFade.is_fading = False
                SceneFade.counter = 0

        # Execute the function asociated
        if not SceneFade.executed and Fade.reverse:
            SceneFade.executed = True
            SceneFade.function(*SceneFade.arguments)

        # Update the fade
        SceneFade.fades.update(delta_time)

    def draw(self, screen):
        # Draw the fade
        SceneFade.fades.draw(screen)
Exemple #14
0
    def show_groups(self, userid):
        self.connect()
        cursor = self.cnx.cursor()

        query = ("SELECT groupname.gid, groupname.groupname "
                 "FROM persongroup "
                 "join groupname on persongroup.gid = groupname.gid "
                 "WHERE id = %s")

        cursor.execute(query, (userid, ))

        groups = []

        for (row) in cursor:
            group = Group(gid=row[0], groupname=row[1])
            groups.append(group)

        cursor.close()
        self.cnx.commit()
        self.disconnect()

        return groups
Exemple #15
0
    def get_unjoined_groups(self, userid):
        self.connect()
        cursor = self.cnx.cursor()

        query = (
            "select distinct groupname.gid, groupname.groupname from groupname "
            "join persongroup on groupname.gid = persongroup.gid "
            "where groupname.gid not in (select gid from persongroup where id = %s)"
        )

        cursor.execute(query, (userid, ))

        groups = []

        for (row) in cursor:
            group = Group(gid=row[0], groupname=row[1])
            groups.append(group)

        cursor.close()
        self.cnx.commit()
        self.disconnect()

        return groups
Exemple #16
0
 def get_groups_admin(self, admin_id):
     groups = self.db["groups"].find({"admins": admin_id}, {"_id": 0})
     return [Group(**group) for group in groups]
Exemple #17
0
 def get_groups(self):
     groups = self.db["groups"].find({}, {"_id": 0})
     return [Group(**group) for group in groups]