Skip to content

Commit

Permalink
Add LeaverLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
ShroomAgent27 committed Dec 28, 2023
1 parent b7618f0 commit 5d8dc81
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ To add the cogs to your instance please do: `[p]repo add shroomdog27 https://git
### Cogs
| Name | Status/Version | Description (Click to see full status)
| --- | --- | --- |
| nvite | **1** | <details><summary>Allows creation of invites using custom parameters to force users to use the same settings every time.</summary></details>|
| PrivateChannel| **2** | <details><summary>Allows you to create a private text channel under a configurable category for a given user.</summary></details>|
| VCLogger| **2** | <details><summary>Logs all voice channel joins and leaves in your server. Sends to a configurable channel.</summary></details>|
| nvite | **1** | <details><summary>Allows creation of invites using custom parameters to force users to use the same settings every time.</summary></details>|

| LeaverLogger | **1** | <details><summary>Logs all leaves of the server.</summary></details>|
You can post questions to the issues tab on this board.
27 changes: 27 additions & 0 deletions leaverlogger/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Modified MIT License (MIT)
#
# Copyright (c) 2020 shroomdog27
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, and sublicense
# the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from .leaverlogger import LeaverLoggerCog
from redbot.core.bot import Red


async def setup(bot: Red) -> None:
await bot.add_cog(LeaverLoggerCog())
28 changes: 28 additions & 0 deletions leaverlogger/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"author":[
"shroomdog27"
],
"name":"LeaverLogger",
"description":"Logs to a join/leave message to a channel when someone leaves a voice channel.",
"min_bot_version":"3.3.10",
"max_bot_version":"0.0.0",
"min_python_version":[
3,
8,
5
],
"hidden":false,
"disable":false,
"required_cogs":{

},
"requirements":[

],
"tags":[
"mod",
"logs",
"modlogs"
],
"type":"COG"
}
76 changes: 76 additions & 0 deletions leaverlogger/leaverlogger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Modified MIT License (MIT)
#
# Copyright (c) 2020 shroomdog27
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, and sublicense
# the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import discord
import time
from redbot.core import commands as Commands
from redbot.core import Config
from redbot.core.utils.chat_formatting import inline


class LeaverLoggerCog(Commands.Cog):
"""My custom cog"""

def __init__(self):
self.config = Config.get_conf(self, identifier=458459923910065184)

async def get_channel(self, guild: discord.Guild) -> discord.TextChannel:
txt_id = await self.config.guild(guild).channel()
text_channel = guild.get_channel(txt_id)
return text_channel

async def set_channel(self, guild: discord.Guild, text_channel_id: int):
await self.config.guild(guild).channel.set(text_channel_id)

@Commands.group()
@Commands.guild_only()
async def leaverset(self, ctx):
"""Root command for Voice Chat Logger Commands"""
pass

@leaverset.command(name="channel")
async def leaverset_channel(self, ctx, txt_channel: discord.TextChannel):
"""Sets the text channel to send messages to"""
vc_id = txt_channel.id
await self.set_channel(ctx.guild, vc_id)
await ctx.tick()
return

@Commands.Cog.listener("on_raw_member_remove")
async def on_raw_member_remove(self, payload: discord.RawMemberRemoveEvent) -> None:
member = payload.user # discord.member.Member
guild = member.guild

if guild.id != payload.guild_id:
return

if member.bot:
return

v_emoji = "⬅️"
v_time = "<t:" + str(int(time.time())) + ":f>"
v_user = "**" + str(member) + "**"
v_action = "has left the server."

msg = "{emoji} {t_time} {user} {action}".format(emoji=v_emoji, t_time=v_time, user=v_user, action=v_action)
s_channel = await self.get_channel(guild)
await s_channel.send(msg, allowed_mentions=discord.AllowedMentions.none())
return

0 comments on commit 5d8dc81

Please sign in to comment.