Leaver updated to v3, nudity initial commit, lseen update

pull/14/head
bobloy 7 years ago
parent 743b2ec318
commit 429e0706bd

@ -12,7 +12,7 @@ Cog Function
| forcemention | **Alpha** | <details><summary>Mentions unmentionable roles</summary>Very simple cog, mention doesn't persist</details> | | forcemention | **Alpha** | <details><summary>Mentions unmentionable roles</summary>Very simple cog, mention doesn't persist</details> |
| hangman | **Alpha** | <details><summary>Play a game of hangman</summary>Some visual glitches and needs more customization</details> | | hangman | **Alpha** | <details><summary>Play a game of hangman</summary>Some visual glitches and needs more customization</details> |
| howdoi | **Incomplete** | <details><summary>Create temporary marks on users that expire after specified time</summary>Not yet ported to v3</details> | | howdoi | **Incomplete** | <details><summary>Create temporary marks on users that expire after specified time</summary>Not yet ported to v3</details> |
| leaver | **Incomplete** | <details><summary>Send a message in a channel when a user leaves the server</summary>Not yet ported to v3</details> | | leaver | **Alpha** | <details><summary>Send a message in a channel when a user leaves the server</summary>Just released, please report bugs</details> |
| lseen | **Alpha** | <details><summary>Track when a member was last online</summary>Alpha release, please report bugs</details> | | lseen | **Alpha** | <details><summary>Track when a member was last online</summary>Alpha release, please report bugs</details> |
| reactrestrict | **Alpha** | <details><summary>Removes reactions by role per channel</summary>A bit clunky, but functional</details> | | reactrestrict | **Alpha** | <details><summary>Removes reactions by role per channel</summary>A bit clunky, but functional</details> |
| sayurl | **Alpha** | <details><summary>Convert any URL into text and post to discord</summary>No error checking and pretty spammy</details> | | sayurl | **Alpha** | <details><summary>Convert any URL into text and post to discord</summary>No error checking and pretty spammy</details> |

@ -0,0 +1,5 @@
from .leaver import Leaver
def setup(bot):
bot.add_cog(Leaver(bot))

@ -1,9 +1,20 @@
{ {
"AUTHOR": "Bobloy", "author": [
"INSTALL_MSG": "Thank you for installing leaver", "Bobloy"
"NAME": "Leaver", ],
"SHORT": "Sends message on leave", "bot_version": [
"DESCRIPTION": "Keeps track of when people leave the server, and posts a message notifying", 3,
"TAGS": ["fox", "bobloy", "utilities", "tools", "tool"], 0,
"HIDDEN": false 0
],
"description": "Keeps track of when people leave the server, and posts a message notifying",
"hidden": false,
"install_msg": "Thank you for installing Leaver. Get started with `[p]help Leaver`",
"requirements": [],
"short": "Send message on leave",
"tags": [
"bobloy",
"utils",
"tools"
]
} }

@ -1,10 +1,7 @@
import discord import discord
import os
from datetime import datetime
from redbot.core import Config, checks, commands
from .utils.dataIO import dataIO from redbot.core.commands import Context
from .utils import checks
class Leaver: class Leaver:
@ -12,67 +9,32 @@ class Leaver:
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
self.path = "data/Fox-Cogs/leaver" self.config = Config.get_conf(self, identifier=9811198108111121, force_registration=True)
self.file_path = "data/Fox-Cogs/leaver/leaver.json" default_guild = {
self.the_data = dataIO.load_json(self.file_path) "channel": ''
}
def save_data(self): self.config.register_guild(**default_guild)
"""Saves the json"""
dataIO.save_json(self.file_path, self.the_data)
@commands.group(aliases=['setleaver'], pass_context=True, no_pm=True) @commands.group(aliases=['setleaver'])
@checks.mod_or_permissions(administrator=True) @checks.mod_or_permissions(administrator=True)
async def leaverset(self, ctx): async def leaverset(self, ctx):
"""Adjust leaver settings""" """Adjust leaver settings"""
server = ctx.message.server
if server.id not in self.the_data:
self.the_data[server.id] = {}
self.save_data()
if ctx.invoked_subcommand is None: if ctx.invoked_subcommand is None:
await self.bot.send_cmd_help(ctx) await ctx.send_help()
@leaverset.command(pass_context=True, no_pm=True) @leaverset.command()
async def channel(self, ctx): async def channel(self, ctx: Context):
server = ctx.message.server guild = ctx.guild
if 'CHANNEL' not in self.the_data[server.id]: await self.config.guild(guild).channel.set(ctx.channel.id)
self.the_data[server.id]['CHANNEL'] = '' await ctx.send("Channel set to " + ctx.channel.name)
async def when_leave(self, member: discord.Member):
server = member.guild
channel = await self.config.guild(server).channel()
self.the_data[server.id]['CHANNEL'] = ctx.message.channel.id if channel != '':
self.save_data() channel = server.get_channel(channel)
await self.bot.say("Channel set to "+ctx.message.channel.name) await channel.send(str(member) + "(*" + str(member.nick) + "*) has left the server!")
async def when_leave(self, member):
server = member.server
if server.id in self.the_data:
await self.bot.send_message(server.get_channel(self.the_data[server.id]['CHANNEL']),
str(member) + "(*" + str(member.nick) +"*) has left the server!")
else: else:
await self.bot.send_message(server.default_channel.id, str(member) + " (*" + str(member.nick) +"*) has left the server!") pass
def check_folders():
if not os.path.exists("data/Fox-Cogs"):
print("Creating data/Fox-Cogs folder...")
os.makedirs("data/Fox-Cogs")
if not os.path.exists("data/Fox-Cogs/leaver"):
print("Creating data/Fox-Cogs/leaver folder...")
os.makedirs("data/Fox-Cogs/leaver")
def check_files():
if not dataIO.is_valid_json("data/Fox-Cogs/leaver/leaver.json"):
dataIO.save_json("data/Fox-Cogs/leaver/leaver.json", {})
def setup(bot):
check_folders()
check_files()
q = Leaver(bot)
bot.add_listener(q.when_leave, "on_member_remove")
bot.add_cog(q)

@ -10,7 +10,7 @@ from redbot.core import commands
class LastSeen: class LastSeen:
""" """
V3 Cog Template Report when a user was last seen online
""" """
online_status = discord.Status.online online_status = discord.Status.online

@ -0,0 +1,5 @@
from .nudity import Nudity
def setup(bot):
bot.add_cog(Nudity(bot))

@ -0,0 +1,20 @@
{
"author": [
"Bobloy"
],
"bot_version": [
3,
0,
0
],
"description": "Keep track of when users were last seen online",
"hidden": true,
"install_msg": "Thank you for installing LastSeen. Get started with `[p]help LastSeen`",
"requirements": [],
"short": "Last seen tracker",
"tags": [
"bobloy",
"utils",
"tools"
]
}

@ -0,0 +1,90 @@
from datetime import datetime
import dateutil.parser
import discord
from redbot.core import Config
from redbot.core import commands
from redbot.core.bot import Red
class Nudity:
"""
V3 Cog Template
"""
online_status = discord.Status.online
offline_status = discord.Status.offline
def __init__(self, bot: Red):
self.bot = bot
self.config = Config.get_conf(self, identifier=9811198108111121, force_registration=True)
default_global = {}
default_guild = {
"enabled": True
}
default_member = {
"seen": None
}
self.config.register_global(**default_global)
self.config.register_guild(**default_guild)
self.config.register_member(**default_member)
@staticmethod
def get_date_time(s):
d = dateutil.parser.parse(s)
return d
@commands.group(aliases=['setlseen'], name='lseenset')
async def lset(self, ctx: commands.Context):
"""Change settings for lseen"""
if ctx.invoked_subcommand is None:
await ctx.send_help()
@lset.command(name="toggle")
async def lset_toggle(self, ctx: commands.Context):
"""Toggles tracking seen for this server"""
enabled = not await self.config.guild(ctx.guild).enabled()
await self.config.guild(ctx.guild).enabled.set(
enabled)
await ctx.send(
"Seen for this server is now {}".format(
"Enabled" if enabled else "Disabled"))
@commands.command(aliases=['lastseen'])
async def lseen(self, ctx: commands.Context, member: discord.Member):
"""
Just says the time the user was last seen
"""
if member.status != self.offline_status:
last_seen = datetime.utcnow()
else:
last_seen = await self.config.member(member).seen()
if last_seen is None:
await ctx.send(embed=discord.Embed(description="I've never seen this user"))
return
last_seen = self.get_date_time(last_seen)
# embed = discord.Embed(
# description="{} was last seen at this date and time".format(member.display_name),
# timestamp=self.get_date_time(last_seen))
embed = discord.Embed(timestamp=last_seen)
await ctx.send(embed=embed)
# async def on_socket_raw_receive(self, data):
# try:
# if type(data) == str:
# raw = json.loads(data)
# print(data)
# except:
# print(data)
async def on_member_update(self, before: discord.Member, after: discord.Member):
if before.status != self.offline_status and after.status == self.offline_status:
if not await self.config.guild(before.guild).enabled():
return
await self.config.member(before).seen.set(datetime.utcnow().isoformat())
Loading…
Cancel
Save