Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added database/pet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added database/sommie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,31 @@ services:
ninian:
image: registry.froginata.com/ninian:${IMAGE_TAG}
restart: unless-stopped
depends_on:
- database
environment:
DATABASE_CONNECTION: "postgresql://ninian:${POSTGRES_PASSWORD}@database/bot_db"
OWNER_ID: ${OWNER_ID}
TOKEN: ${TOKEN}
labels:
- "com.centurylinklabs.watchtower.scope=ninian-${IMAGE_TAG}"
networks:
- nininet

database:
image: postgres:17
restart: unless-stopped
environment:
POSTGRES_DB: bot_db
POSTGRES_USER: ninian
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
networks:
- nininet
ports:
- 5432:5432
volumes:
- db:/var/lib/postgresql/data

watchtower:
image: containrrr/watchtower
restart: unless-stopped
Expand All @@ -19,3 +39,12 @@ services:
- "com.centurylinklabs.watchtower.enable=false"
volumes:
- /var/run/docker.sock:/var/run/docker.sock

networks:
nininet:
name: "nininet-${IMAGE_TAG}"
driver: bridge

volumes:
db:
name: "ninian-db-${IMAGE_TAG}"
36 changes: 5 additions & 31 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,9 @@ async def random_command(ctx):

class SommieButton(maji.Button):
def action(self, interaction):
user = oifey.user.get(-1)

if not "sommie" in user:
user["sommie"] = 0

user["sommie"] += 1

oifey.user.update(-1, user)

oifey.sql.User(interaction.user.id).pet_sommie()
edit = self.parent.pages[1]

edit.description = edit.description.format(user["sommie"])

edit.description = edit.description.format(oifey.sql.sommie_pets())
super().action(interaction)

async def sommie(ctx):
Expand All @@ -115,31 +105,17 @@ async def sommie(ctx):

await multi.send(ctx)

@maji.commands.classic("sommie_set")
async def sommie_set(ctx):
if ctx.author.id != client.owner:
return

user = oifey.user.get(-1)

user["sommie"] = int(ctx.content)

oifey.user.update(-1, user)

engage.special["sommie"] = sommie

# ninian
fe6 = oifey.modules["fe6"]

async def ninian(ctx):
embed = maji.Embed()

embed.attach("image", "database/ninian.png")

return embed

fe6.special["ninian"] = ninian

fe6.special["you"] = ninian

# lorenz
Expand Down Expand Up @@ -167,12 +143,10 @@ async def b2(ctx):
b2 = oifey.modules["b2"]

async def lorenz(ctx):
if ctx.content.lower().strip() == "b2 lorenz" or ctx.content.lower().strip() == 'lorenz':
embed = maji.Embed()

embed.attach("image", "database/lorenz.gif")

embed = maji.Embed()
embed.attach("image", "database/lorenz.gif")
return embed

fe3.special["b2 lorenz"] = lorenz
b2.special["lorenz"] = lorenz

Expand Down
2 changes: 0 additions & 2 deletions oifey/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@
import oifey.alias as alias

modules = module.modules
user = sql.user
server = sql.server
133 changes: 46 additions & 87 deletions oifey/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,117 +7,78 @@

search_text = util.text.search_text

character_min = 3
character_max = 30
character_min = 1
character_max = 64

alias_limit = 30
alias_limit = 100

# ADD
async def add_alias(ctx, table, name, og, alias):
row = table.get(name)
if not "alias" in row: row["alias"] = []
async def add_alias(ctx, author_id, og, alias):
user = sql.User(author_id)

if len(row["alias"]) >= alias_limit:
if len(user.custom_aliases) >= alias_limit:
embed = maji.Embed(title = "Alias limit reached!", desc = "Maybe try removing old ones?", color = embed_color)

await ctx.send(embed=embed)

return

def remove(data):
for x in sql.banned_words:
data = data.replace(x, "")

return data

og = remove(og)
alias = remove(alias)

def check(data):
clean = search_text(data, ignore_space = True)

# character size limits
return len(clean) >= character_min and len(clean) <= character_max

return character_min <= len(data) <= character_max

if check(og) and check(alias):
add = {
"og": {"clean": search_text(og, ignore_space = True), "display": og},
"alias": {"clean": search_text(alias, ignore_space = True), "display": alias},
}

row["alias"].append(add)

table.update(name, row)

embed = maji.Embed(title = "Success", desc = "Alias added!", color = embed_color)
await ctx.send(embed=embed)

try:
user.add_alias(alias, og)
embed = maji.Embed(title = "Success", desc = "Alias added!", color = embed_color)
except Exception as e:
print(e)
embed = maji.Embed(title="Error", desc="Your alias couldn't be added. Please report this to staff!", color=embed_color)
else:
embed = maji.Embed(title = "Error", desc = f"Your alias couldn't be added. Please check if it is at least {character_min} characters, and most special characters are ignored!", color = embed_color)
await ctx.send(embed=embed)
embed = maji.Embed(title = "Error", desc = f"Your alias couldn't be added. Please keep it under {character_max} characters long.", color = embed_color)

await ctx.send(embed=embed)

# SHOW
async def show_alias(ctx, table, name):
row = table.get(name)
row = row.get("alias") or []
async def show_alias(ctx, author_id):
user = sql.User(author_id)

if not row:
embed = maji.Embed(title = "No aliases yet!", desc = "There's still no aliases here.\nIf you're looking at adding alias for yourself, use /alias user.\nIf you're looking at adding aliases for a server, only people that can manage messages can add/remove them, with the command being /alias server.", color = embed_color)

await ctx.send(embed=embed)

if not user.custom_aliases:
embed = maji.Embed(title = "No aliases yet!", desc = "There's still no aliases here.\nIf you're looking at adding alias for yourself, use /alias user.\nIf you're looking at adding aliases for a server, you can't, yet.", color = embed_color)
else:
text = ""

i = 1
for value in row:
og = value["og"]["display"]
alias = value["alias"]["display"]

for alias, og in user.custom_aliases:
text += f"**{i}.** `{alias}` is an alias to `{og}`\n"

i += 1

embed = maji.Embed(title = f"Alias {len(row)}/{alias_limit}", desc = text, footer = "Type / if you want to add more or remove them!", color = embed_color)
embed = maji.Embed(title = f"Alias usage {len(user.custom_aliases)}/{alias_limit}", desc = text, footer = "Type / if you want to add more or remove them!", color = embed_color)

await ctx.send(embed=embed)
await ctx.send(embed=embed)

# REMOVE
async def remove_alias(ctx, table, name, index = 0):
row = table.get(name)
if not "alias" in row: row["alias"] = []

alias = row["alias"]

index = max(index - 1, 0)

if alias and index < len(alias):
alias.pop(index)

table.update(name, row)

embed = maji.Embed(title = "Success", desc = "Alias removed!", color = embed_color)

await ctx.send(embed=embed)

async def remove_alias(ctx, author_id, alias):
user = sql.User(author_id)
if alias not in user.custom_aliases:
embed = maji.Embed(title="Error", desc="Could not find that alias to remove!", color=embed_color)
else:
embed = maji.Embed(title = "Invalid index!", desc = "It's too high, or maybe you didn't even add any aliases yet.", color = embed_color)

await ctx.send(embed=embed)
try:
user.remove_alias(alias)
embed = maji.Embed(title = "Success", desc = "Alias removed!", color = embed_color)
except Exception as e:
print(e)
embed = maji.Embed(title="Error", desc="Your alias couldn't be removed. Please report this to staff!", color=embed_color)
await ctx.send(embed=embed)

# Command funcs
# user
async def user_add(ctx, options = {}):
await add_alias(ctx, sql.user, ctx.author.id, options["name"], options["alias"])
await add_alias(ctx, ctx.author.id, options["name"], options["alias"])

async def user_show(ctx, options = {}):
await show_alias(ctx, sql.user, ctx.author.id)
async def user_show(ctx):
await show_alias(ctx, ctx.author.id)

async def user_remove(ctx, options = {}):
await remove_alias(ctx, sql.user, ctx.author.id, options["index"])
await remove_alias(ctx, ctx.author.id, options["alias"])

# server
"""
async def server_add(ctx, options = {}):
if ctx.guild is None or not ctx.channel.permissions_for(ctx.author).manage_messages: return

Expand All @@ -132,7 +93,7 @@ async def server_remove(ctx, options = {}):
if ctx.guild is None or not ctx.channel.permissions_for(ctx.author).manage_messages: return

await remove_alias(ctx, sql.server, ctx.guild.id, options["index"])
"""

# Options
add_options = [
Expand All @@ -152,20 +113,18 @@ async def server_remove(ctx, options = {}):

remove_options = [
{
"name": "index",
"description": "Which alias to remove (you can see the index in the show command).",
"name": "alias",
"description": "Which alias to remove.",
"type": 4,
"required": True
}
]

# Add Commands
# user
#maji.commands.add_slash(user_add, "add", desc="User | Adds an alias for something.", group="alias", subgroup="user", options=add_options)

#maji.commands.add_slash(user_show, "show", desc="User | Shows all active aliases.", group="alias", subgroup="user")

#maji.commands.add_slash(user_remove, "remove", desc="User | Removes an alias.", group="alias", subgroup="user", options=remove_options)
maji.commands.add_slash(user_add, "add", desc="User | Adds an alias for something.", group="alias", subgroup="user", options=add_options)
maji.commands.add_slash(user_show, "show", desc="User | Shows all active aliases.", group="alias", subgroup="user")
maji.commands.add_slash(user_remove, "remove", desc="User | Removes an alias.", group="alias", subgroup="user", options=remove_options)

# server
#maji.commands.add_slash(server_add, "add", desc="Server | Adds an alias for something.", group="alias", subgroup="server", options=add_options)
Expand Down
43 changes: 20 additions & 23 deletions oifey/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,56 +235,53 @@ def append_alt(k, v):
def search(self, og_text, ctx = None) -> SearchResult:
# if context exists to get aliases from
if ctx:
text = util.text.search_text(og_text, ignore_space = True)
text = util.text.search_text(og_text)

# organize aliases
aliases = sql.user.get(ctx.author.id).get("alias") or []

aliases = sql.User(ctx.author.id).custom_aliases

"""
if ctx.guild:
guild = sql.server.get(ctx.guild.id).get("alias") or []

aliases = aliases + guild

for value in aliases: # loop in order
original = value["og"]["clean"] #original
alias = value["alias"]["clean"] #alias

"""

for k, v in aliases:
alias = util.text.search_text(k)
original = util.text.search_text(v)

# find alias that is between whitespace or/and
# has 0-2 numbers in the end
regex = r"\b" + alias + r"\d{0,2}\b"

regex = re.search(regex, text)

# ^ regex jank to find if the name is in the text

# if it finds it, replace it with the alias
if regex:
new = regex.group(0).replace(alias, original)

text = text[:regex.start()] + new + text[regex.end():]

text = util.text.search_text(text)


else:
text = util.text.search_text(og_text)

finds = []

# Pick a random entry
if text.startswith("random") and (not(ctx) or ctx.allow_random):
if text.startswith("random") and (not ctx or ctx.allow_random):
finds.append(self.random_pick())

# try searching if it's a hard alt name
elif text in self.hard:
finds.append(self.hard[text])

elif text:
for key, value in self.alt.items():
for name in value:
if text in name:
finds.append(self.items[key])
break

return SearchResult(finds, self, og_text)

def random_pick(self):
Expand Down
Loading