Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various fixes and consistency:tm: #37

Merged
merged 9 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions cogs/commands/misc/canister.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def search(query):

"""
async with aiohttp.ClientSession() as client:
async with client.get(f'https://api.canister.me/v1/community/packages/search?query={urllib.parse.quote(query)}&searchFields=name,author,maintainer&responseFields=identifier,header,tintColor,name,price,description,packageIcon,repository.uri,repository.name,author,maintainer,latestVersion,nativeDepiction,depiction') as resp:
async with client.get(f'https://api.canister.me/v1/community/packages/search?query={urllib.parse.quote(query)}&searchFields=identifier,name&responseFields=identifier,header,tintColor,name,price,description,packageIcon,repository.uri,repository.name,author,maintainer,latestVersion,nativeDepiction,depiction') as resp:
if resp.status == 200:
response = json.loads(await resp.text())
if response.get('status') == "Successful":
Expand Down Expand Up @@ -137,7 +137,10 @@ async def on_message(self, message):
result = list(await search(search_term))

if not result:
await ctx.send_error("That package wasn't found in Canister's database.")
embed = discord.Embed(
title=":(\nI couldn't find that package", color=discord.Color.red())
embed.description = f"Try broadening your search query."
await ctx.send(embed=embed, delete_after=8)
return

view = discord.ui.View(timeout=30)
Expand Down Expand Up @@ -175,8 +178,11 @@ async def package(self, ctx: BlooContext, query: Option(str, description="Name o
result = list(await search(query))

if not result:
raise commands.BadArgument(
"That package wasn't found in Canister's database.")
embed = discord.Embed(
title=":(\nI couldn't find that package", color=discord.Color.red())
embed.description = f"Try broadening your search query."
await ctx.respond(embed=embed)
return

view = discord.ui.View(timeout=30)
td = TweakDropdown(ctx.author, result, interaction=True,
Expand Down
4 changes: 3 additions & 1 deletion cogs/commands/misc/memes.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def __init__(self, bot):
self.memegen_cooldown = CooldownMapping.from_cooldown(
1, 45, MessageTextBucket.custom)
self.markov_lock = Lock()
self.meme_phrases = ["{user}, have a look at this funny meme! LOL!", "Hey, {user}. Have a look at this knee-slapper!",
"{user}, look at this meme! Just don't show Aaron.", "{user} 😂😂😂😂😭😭😭😭"]

@slash_command(guild_ids=[cfg.guild_id], description="Display a meme")
async def meme(self, ctx: BlooContext, name: Option(str, description="Meme name", autocomplete=memes_autocomplete), user_to_mention: Option(discord.Member, description="User to mention in the response", required=False)):
Expand Down Expand Up @@ -88,7 +90,7 @@ async def meme(self, ctx: BlooContext, name: Option(str, description="Meme name"
file), filename="image.gif" if meme.image.content_type == "image/gif" else "image.png")

if user_to_mention is not None:
title = f"{user_to_mention.mention}, have a look at this funny meme! LOL!"
title = random.choice(self.meme_phrases).format(user=user_to_mention.mention)
else:
title = None

Expand Down
26 changes: 21 additions & 5 deletions cogs/monitors/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ async def fetch_cij_or_news_database(self):
async def detect_cij_or_eta(self, message: discord.Message, db_guild):
if message.edited_at is not None:
return
if permissions.has(message.guild, message.author, 2):
if permissions.has(message.guild, message.author, 1):
return

cij_filter_response = await self.fetch_cij_or_news_database()
Expand All @@ -354,21 +354,37 @@ async def detect_cij_or_eta(self, message: discord.Message, db_guild):
subject_and_word_in_message = any(
v in text for v in verb) and any(s in text for s in subject)

if any(intent in text for intent in intent_news) and subject_and_word_in_message:
if (any(intent in text for intent in intent_news) and subject_and_word_in_message or any(intent in text for intent in intent_cij) and subject_and_word_in_message) and message.channel.id == guild_service.get_guild().channel_general:
view = discord.ui.View()
embed = discord.Embed(color=discord.Color.orange())
embed.description = f"Please keep support or jailbreak related messages in the appropriate channels. Thanks!"
embed.set_footer(
text="This action was performed automatically. Please disregard if incorrect.")
view.add_item(discord.ui.Button(label='Genius Bar', emoji="<:Genius:947545923028922448>",
url=f"https://discord.com/channels/349243932447604736/688124678707216399", style=discord.ButtonStyle.url))
view.add_item(discord.ui.Button(label='Jailbreak Channel', emoji="<:Channel2:947546361715388417>",
url=f"https://discord.com/channels/349243932447604736/688122301975363591", style=discord.ButtonStyle.url))
res = await message.reply(embed=embed, view=view, delete_after=20)
elif any(intent in text for intent in intent_news) and subject_and_word_in_message:
embed = discord.Embed(color=discord.Color.orange())
embed.description = f"It appears you are asking about future jailbreaks. Nobody knows when a jailbreak will be released, but you can subscribe to notifications about releases by going to <#{db_guild.channel_reaction_roles}>."
embed.set_footer(
text="This action was performed automatically. Please disregard if incorrect.")
#view = DissmissableMessage(message.author)
res = await message.reply(embed=embed)
res = await message.reply(embed=embed, delete_after=20)
#view.start(res)
elif any(intent in text for intent in intent_cij) and subject_and_word_in_message:
embed = discord.Embed(color=discord.Color.orange())
embed.description = "It appears you are asking if you can jailbreak your device, you can find out that information by using `/canijailbreak` or in the \"Get Started\" section of [ios.cfw.guide](https://ios.cfw.guide/get-started)."
embed.description = "It appears you are asking if you can jailbreak your device, you can find out that information by using `/canijailbreak` or in the \"Get Started\" section of ios.cfw.guide."
embed.set_footer(
text="This action was performed automatically. Please disregard if incorrect.")
view = discord.ui.View()
view.add_item(discord.ui.Button(label='Get Started', emoji="<:Guide:947350624385794079>",
url=f"https://ios.cfw.guide/get-started/#required-reading", style=discord.ButtonStyle.url))
view.add_item(discord.ui.Button(label='Jailbreak Chart', emoji="<:Search2:947525874297757706>",
url=f"https://appledb.dev/", style=discord.ButtonStyle.url))
#view = DissmissableMessage(message.author)
res = await message.reply(embed=embed)
res = await message.reply(embed=embed, view=view, delete_after=20)
#view.start(res)

@generate_report_msg.error
Expand Down
75 changes: 53 additions & 22 deletions cogs/monitors/jailbreak_monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from utils.logger import logger
from utils.permissions.permissions import permissions
from utils.views.canister import default_repos
from utils.config import cfg
from yarl import URL


Expand All @@ -20,10 +21,16 @@ def __init__(self, bot):

@commands.Cog.listener()
async def on_message(self, message):
if message.guild.id is None:
return
if message.guild.id != cfg.guild_id:
return
if message.author.bot:
return
if message.channel.id == guild_service.get_guild().channel_general and not permissions.has(message.guild, message.author, 5):
return
if 'sileo://package/' in message.content: # Stops double messages when a package and repo URL are in the same message
return

url = re.search(r'(https?://\S+)', message.content)
if url is None:
Expand All @@ -45,7 +52,7 @@ async def on_message(self, message):
url=f"https://sharerepo.stkc.win/v2/?pkgman=sileo&repo={potential_repo}", style=discord.ButtonStyle.url))
view.add_item(discord.ui.Button(label='Add Repo to Zebra', emoji="<:zebra:911433583032422420>",
url=f"https://sharerepo.stkc.win/v2/?pkgman=zebra&repo={potential_repo}", style=discord.ButtonStyle.url))
view.add_item(discord.ui.Button(label='Other Package Managers', emoji=":cydiasileosplit:932650041099825232",
view.add_item(discord.ui.Button(label='Other Package Managers', emoji="<:Add:947354227171262534>",
url=f"https://sharerepo.stkc.win/?repo={potential_repo}", style=discord.ButtonStyle.url))

await message.reply(file=discord.File("data/images/transparent1x1.png"), view=view, mention_author=False)
Expand Down Expand Up @@ -91,6 +98,10 @@ def __init__(self, bot):

@commands.Cog.listener()
async def on_message(self, message):
if message.guild.id is None:
return
if message.guild.id != cfg.guild_id:
return
if message.author.bot:
return
if message.channel.id == guild_service.get_guild().channel_general and not permissions.has(message.guild, message.author, 5):
Expand All @@ -101,31 +112,51 @@ async def on_message(self, message):
if urlscheme is None:
return

try:
async with aiohttp.ClientSession() as client:
async with client.get(URL(f'https://api.parcility.co/db/package/{urlscheme.group(1)}', encoded=True)) as resp:
if resp.status == 200:
response = json.loads(await resp.text())
async with aiohttp.ClientSession() as client:
async with client.get(f'https://api.canister.me/v1/community/packages/search?query={urlscheme.group(1)}&searchFields=identifier&responseFields=name,repository.uri,repository.name,depiction,packageIcon,tintColor') as resp:
if resp.status == 200:
response = json.loads(await resp.text())
data = response.get('data')

if not data:
view = discord.ui.View()
embed = discord.Embed(
title=":(\nI couldn't find that package", color=discord.Color.orange())
embed.description = f"You have sent a link to a package, you can use the button below to open it directly in Sileo."
view.add_item(discord.ui.Button(label='View Package in Sileo', emoji="<:Search2:947525874297757706>",
url=f"https://sharerepo.stkc.win/v3/?pkgid={urlscheme.group(1)}", style=discord.ButtonStyle.url))
await message.reply(embed=embed, view=view, mention_author=False)
return

canister = response['data'][0]
color = canister.get('tintColor')
view = discord.ui.View()

if color is None:
color = discord.Color.blue()

else:
color = discord.Color(int(color.strip('#'), 16))
embed = discord.Embed(
title=f"{response.get('data')['Name']} - {response.get('data')['repo']['label']}", color=discord.Color.green())
embed.description = f"You have linked to a package, you can use the above link to open it directly in Sileo."
embed.set_thumbnail(url=response.get('data')['Icon'])
title=f"{canister.get('name')} - {canister.get('repository')['name']}", color=color)
embed.description = f"You have sent a link to a package, you can use the button below to open it directly in Sileo."
icon = canister.get('packageIcon')
depiction = canister.get('depiction')
view.add_item(discord.ui.Button(label='View Package in Sileo', emoji="<:Search2:947525874297757706>",
url=f"https://sharerepo.stkc.win/v3/?pkgid={urlscheme.group(1)}", style=discord.ButtonStyle.url))

if depiction is not None:
view.add_item(discord.ui.Button(label='View Depiction', emoji="<:Depiction:947358756033949786>", url=canister.get(
'depiction'), style=discord.ButtonStyle.url))

if icon is not None:
embed.set_thumbnail(url=canister.get('packageIcon'))

view.add_item(discord.ui.Button(label='Add Repo to Sileo', emoji="<:sileo:679466569407004684>",
url=f"https://sharerepo.stkc.win/v2/?pkgman=sileo&repo={response.get('data')['repo']['url']}", style=discord.ButtonStyle.url))
try:
view.add_item(discord.ui.Button(label='View Depiction', emoji="🔎", url=response.get(
'data')['Depiction'], style=discord.ButtonStyle.url))
except:
view.add_item(discord.ui.Button(
label='View on Parcility', url=f"https://parcility.co/package/{urlscheme.group(1)}", style=discord.ButtonStyle.url))
await message.reply(f'<sileo://package/{urlscheme.group(1)}>', embed=embed, view=view, allowed_mentions=discord.AllowedMentions(users=True))
except:
embed = discord.Embed(title=f"Unknown Package",
color=discord.Color.green())
embed.description = f"You have linked to a package, you can use the above link to open it directly in Sileo."
await message.reply(f'<sileo://package/{urlscheme.group(1)}>', embed=embed)
url=f"https://sharerepo.stkc.win/v2/?pkgman=sileo&repo={canister.get('repository')['uri']}", style=discord.ButtonStyle.url))
await message.reply(embed=embed, view=view, mention_author=False)




def setup(bot):
Expand Down
4 changes: 3 additions & 1 deletion cogs/monitors/songs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import discord
from discord.ext import commands
import re
import random

from utils.config import cfg
from utils.mod.filter import find_triggered_filters
Expand Down Expand Up @@ -38,6 +39,7 @@ def __init__(self, bot):
# self.spotify_pattern = re.compile(r"[\bhttps://open.\b]spotify[\b.com\b]*[/:]*track[/:]*[A-Za-z0-9]+")
# self.am_pattern = re.compile(r"[\bhttps://music.\b]apple[\b.com\b]*[/:][[a-zA-Z][a-zA-Z]]?[:/]album[/:][a-zA-Z\d%\(\)-]+[/:][\d]{1,10}")
self.pattern = re.compile(r"(https://open.spotify.com/track/[A-Za-z0-9]+|https://music.apple.com/[[a-zA-Z][a-zA-Z]]?/album/[a-zA-Z\d%\(\)-]+/[\d]{1,10}\?i=[\d]{1,15})")
self.song_phrases = ["I like listening to {artist} too!\nHere's \"{title}\"...", "You listen to {artist} too? They're my favorite!\nHere's \"{title}\"..."]

@commands.Cog.listener()
async def on_message(self, message: discord.Message):
Expand Down Expand Up @@ -72,7 +74,7 @@ async def generate_view(self, message: discord.Message, link: str):
title = res.get('entitiesByUniqueId').get(unique_id)

if title is not None:
title = f"I like listening to {title.get('artistName')} too!\nHere's \"{title.get('title')}\"..."
title = random.choice(self.song_phrases).format(artist=title.get('artistName'), title=title.get('title'))
title = discord.utils.escape_markdown(title)
title = discord.utils.escape_mentions(title)

Expand Down
4 changes: 2 additions & 2 deletions utils/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ def refresh_button_state(self):
url=f'https://sharerepo.stkc.win/v2/?pkgman=sileo&repo={self.ctx.repo}', disabled=True, style=discord.ButtonStyle.url, row=1),
discord.ui.Button(label='Cannot add default repo', emoji="<:zebra:911433583032422420>",
url=f'https://sharerepo.stkc.win/v2/?pkgman=zebra&repo={self.ctx.repo}', disabled=True, style=discord.ButtonStyle.url, row=1),
discord.ui.Button(label='Cannot add default repo', emoji="<:cydiasileosplit:932650041099825232>",
discord.ui.Button(label='Cannot add default repo', emoji="<:Add:947354227171262534>",
url=f'https://sharerepo.stkc.win/?repo={self.ctx.repo}', style=discord.ButtonStyle.url, disabled=True, row=1)
]
if self.ctx.depiction:
extra_buttons.insert(0,
discord.ui.Button(label='View Depiction', emoji="🔎",
discord.ui.Button(label='View Depiction', emoji="<:Depiction:947358756033949786>",
url=self.ctx.depiction, style=discord.ButtonStyle.url, row=1),
)

Expand Down
6 changes: 3 additions & 3 deletions utils/views/canister.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def generate_buttons(self, entry):
url=f'https://sharerepo.stkc.win/v2/?pkgman=sileo&repo={repo}', style=discord.ButtonStyle.url),
discord.ui.Button(label='Add Repo to Zebra', emoji="<:zebra:911433583032422420>",
url=f'https://sharerepo.stkc.win/v2/?pkgman=zebra&repo={repo}', style=discord.ButtonStyle.url),
discord.ui.Button(label='Other Package Managers', emoji="<:cydiasileosplit:932650041099825232>",
discord.ui.Button(label='Other Package Managers', emoji="<:Add:947354227171262534>",
url=f'https://sharerepo.stkc.win/?repo={repo}', style=discord.ButtonStyle.url)
]
else:
Expand All @@ -221,12 +221,12 @@ def generate_buttons(self, entry):
url=f'https://sharerepo.stkc.win/v2/?pkgman=sileo&repo={repo}', disabled=True, style=discord.ButtonStyle.url),
discord.ui.Button(label='Cannot add default repo', emoji="<:zebra:911433583032422420>",
url=f'https://sharerepo.stkc.win/v2/?pkgman=zebra&repo={repo}', disabled=True, style=discord.ButtonStyle.url),
discord.ui.Button(label='Cannot add default repo', emoji="<:cydiasileosplit:932650041099825232>",
discord.ui.Button(label='Cannot add default repo', emoji="<:Add:947354227171262534>",
url=f'https://sharerepo.stkc.win/?repo={repo}', disabled=True, style=discord.ButtonStyle.url)
]
if depiction is not None:
extra_buttons.insert(0,
discord.ui.Button(label='View Depiction', emoji="🔎",
discord.ui.Button(label='View Depiction', emoji="<:Depiction:947358756033949786>",
url=depiction, style=discord.ButtonStyle.url),
)
return extra_buttons
Expand Down