Exemplo n.º 1
0
    async def create(
        self,
        ctx,
        name: clean_content,
        tag_type: TagTypeConverter,
        *content: clean_content,
    ):
        """create tag content"""
        with self.bot.session_scope() as session:
            if Tag.exists(name, ctx.guild.id, session):
                raise NerpyException("tag already exists!")

        async with ctx.typing():
            with self.bot.session_scope() as session:
                self.bot.log.info(
                    f"creating tag {ctx.guild.name}/{name} started")
                _tag = Tag(
                    Name=name,
                    Author=str(ctx.author),
                    Type=tag_type,
                    CreateDate=datetime.utcnow(),
                    Count=0,
                    Volume=100,
                    GuildId=ctx.guild.id,
                )

                Tag.add(_tag, session)
                session.flush()

                self._add_tag_entries(session, _tag, content)

            self.bot.log.info(f"creating tag {ctx.guild.name}/{name} finished")
        await self.bot.sendc(ctx, f"tag {name} created!")
Exemplo n.º 2
0
def post(tag_name):
    if Tag.exists(tag_name):
        return error_view(500, "tag already exists")

    new_tag = Tag.new(tag_name)
    new_tag.insert()

    return tag_created_view(new_tag)
Exemplo n.º 3
0
    async def delete(self, ctx, name: clean_content):
        """delete a tag?"""
        self.bot.log.info(f"trying to delete {name} from {ctx.guild.id}")
        with self.bot.session_scope() as session:
            if not Tag.exists(name, ctx.guild.id, session):
                raise NerpyException("tag doesn't exist!")

            Tag.delete(name, ctx.guild.id, session)
        await self.bot.sendc(ctx, "tag deleted!")
Exemplo n.º 4
0
    async def volume(self, ctx, name: clean_content, vol):
        """adjust the volume of a sound tag (WIP)"""
        self.bot.log.info(f"set volume of {name} to {vol} from {ctx.guild.id}")
        with self.bot.session_scope() as session:
            if not Tag.exists(name, ctx.guild.id, session):
                raise NerpyException("tag doesn't exist!")

        with self.bot.session_scope() as session:
            _tag = Tag.get(name, ctx.guild.id, session)
            _tag.Volume = vol
        await self.bot.sendc(ctx, f"changed volume of {name} to {vol}")
Exemplo n.º 5
0
def delete(tag_name):
    if not Tag.exists(tag_name):
        return error_view(404, "tag not found")

    tag = Tag.get(tag_name)
    tag.delete()

    tag_links = TagDnIP.list_from_tag(tag.name)
    for t in tag_links:
        t.delete()

    return tag_deleted_view(tag)
Exemplo n.º 6
0
    async def add(self, ctx, name: clean_content, *content: clean_content):
        """add an entry to an existing tag"""
        with self.bot.session_scope() as session:
            if not Tag.exists(name, ctx.guild.id, session):
                raise NerpyException("tag doesn't exists!")

        async with ctx.typing():
            with self.bot.session_scope() as session:
                _tag = Tag.get(name, ctx.guild.id, session)
                self._add_tag_entries(session, _tag, content)

            self.bot.log.info(f"added entry to tag {ctx.guild.name}/{name}.")
        await self.bot.sendc(ctx, f"Entry added to tag {name}!")
Exemplo n.º 7
0
def post(tag_name, object_key, object_type):
    if TagDnIP.exists(tag_name, object_key, object_type):
        return error_view(500, "tag link already exists")

    if not Tag.exists(tag_name):
        return error_view(404, "source tag not found")

    if object_type == DOMAIN_NAME_COLLECTION:
        object_exists = DomainName.exists(object_key)
    elif object_type == IP_ADDRESS_COLLECTION:
        object_exists = IPAddress.exists(object_key)
    else:
        return error_view(400, "invalid object type")

    if not object_exists:
        return error_view(404, "target object not found")

    new_tag_link = TagDnIP.new(tag_name, object_key, object_type)
    new_tag_link.insert()

    return tag_link_created_view(new_tag_link)