Skip to content

Commit

Permalink
joinping now uses tagscript!
Browse files Browse the repository at this point in the history
  • Loading branch information
i-am-zaidali committed Jun 9, 2023
1 parent 2f15b79 commit c9d5c33
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
6 changes: 4 additions & 2 deletions joinping/info.json
Expand Up @@ -8,7 +8,9 @@
"crayyy_zee"
],
"required_cogs": {},
"requirements": [],
"requirements": [
"git+https://github.com/phenom4n4n/TagScript.git@dpy2"
],
"tags": [
"joinping",
"member join",
Expand All @@ -17,4 +19,4 @@
"mentions"
],
"type": "COG"
}
}
37 changes: 24 additions & 13 deletions joinping/main.py
Expand Up @@ -4,23 +4,22 @@
from redbot.core import Config, commands
from redbot.core.bot import Red
from redbot.core.utils.chat_formatting import box, humanize_list

from .utils import Coordinate
import TagScriptEngine as tse

log = logging.getLogger("red.craycogs.joinping")

guild_defaults = {
"ping_channels": [],
"delete_after": 2,
"ping_message": "{member.mention}",
"ping_message": "{member(mention)}",
}


class JoinPing(commands.Cog):
"""
Ghost ping users when they join."""

__version__ = "1.0.2"
__version__ = "1.1.0"
__author__ = ["crayyy_zee#2900"]

def __init__(self, bot: Red):
Expand Down Expand Up @@ -54,15 +53,27 @@ async def on_member_join(self, member):
if not guild_data.get("ping_channels"):
return

message = guild_data.get("ping_message", "")
engine = tse.AsyncInterpreter([tse.EmbedBlock()])
resp = await engine.process(
message,
seed_variables={
"member": tse.MemberAdapter(member),
"server": tse.GuildAdapter(member.guild),
},
)
if not resp.body and not resp.actions.get("embed"):
return

for i in guild_data.get("ping_channels"):
channel = self.bot.get_channel(i)
if not channel:
continue

message = f"{(guild_data.get('ping_message', '')).format_map(Coordinate(member=member, server=member.guild.name, guild=member.guild.name))}"
try:
await channel.send(
message,
content=resp.body or None,
embed=resp.actions.get("embed"),
delete_after=guild_data.get("delete_after"),
allowed_mentions=discord.AllowedMentions(users=True),
)
Expand Down Expand Up @@ -107,15 +118,15 @@ async def jpset_msg(self, ctx, *, message: str):
"""Set the message that will be sent when a user joins.
Usable placeholders include:
- member (the member that joined)
- member.mention (the mention)
- member.id (the id)
- member.name (the name)
- member.discriminator (the discriminator)
- {member} (the member that joined)
- {member(mention)} (the mention)
- {member(id)} (the id)
- {member(name)} (the name)
- {member(discriminator)} (the discriminator)
- server (the name of the server the member joined)
- {server} (the server the member joined)
These placeholders must be places within `{}` (curly brackets) to be replaced with actual values.
This messsage uses tagscript and allows embed
"""
await self.config.guild(ctx.guild).ping_message.set(message)
await self._build_cache()
Expand Down
18 changes: 0 additions & 18 deletions joinping/utils.py

This file was deleted.

0 comments on commit c9d5c33

Please sign in to comment.