Migrate to newer versions

This commit is contained in:
Zeva Rose 2022-02-19 13:39:31 -07:00
parent 38c0a47086
commit b8d1cb6cfc
10 changed files with 64 additions and 41 deletions

View file

@ -8,8 +8,8 @@ from dis_snek.models.snek.application_commands import (
slash_option, slash_option,
) )
from dis_snek.models.snek.command import check from dis_snek.models.snek.command import check
from jarvis_core.db.models import Kick
from jarvis.db.models import Kick
from jarvis.utils import build_embed from jarvis.utils import build_embed
from jarvis.utils.permissions import admin_or_permissions from jarvis.utils.permissions import admin_or_permissions
@ -65,10 +65,11 @@ class KickCog(Scale):
embed.set_thumbnail(url=user.display_avatar.url) embed.set_thumbnail(url=user.display_avatar.url)
embed.set_footer(text=f"{user.username}#{user.discriminator} | {user.id}") embed.set_footer(text=f"{user.username}#{user.discriminator} | {user.id}")
_ = Kick( k = Kick(
user=user.id, user=user.id,
reason=reason, reason=reason,
admin=ctx.author.id, admin=ctx.author.id,
guild=ctx.guild.id, guild=ctx.guild.id,
).save() )
await k.commit()
await ctx.send(embed=embed) await ctx.send(embed=embed)

View file

@ -74,14 +74,15 @@ class MuteCog(Scale):
return return
await user.timeout(communication_disabled_until=duration, reason=reason) await user.timeout(communication_disabled_until=duration, reason=reason)
_ = Mute( m = Mute(
user=user.id, user=user.id,
reason=reason, reason=reason,
admin=ctx.author.id, admin=ctx.author.id,
guild=ctx.guild.id, guild=ctx.guild.id,
duration=duration, duration=duration,
active=True, active=True,
).save() )
await m.commit()
embed = build_embed( embed = build_embed(
title="User Muted", title="User Muted",

View file

@ -37,12 +37,13 @@ class PurgeCog(Scale):
async for message in ctx.channel.history(limit=amount + 1): async for message in ctx.channel.history(limit=amount + 1):
messages.append(message) messages.append(message)
await ctx.channel.delete_messages(messages, reason=f"Purge by {ctx.author.username}") await ctx.channel.delete_messages(messages, reason=f"Purge by {ctx.author.username}")
_ = Purge( p = Purge(
channel=ctx.channel.id, channel=ctx.channel.id,
guild=ctx.guild.id, guild=ctx.guild.id,
admin=ctx.author.id, admin=ctx.author.id,
count=amount, count=amount,
).save() )
await p.commit()
@slash_command( @slash_command(
name="autopurge", sub_cmd_name="add", sub_cmd_description="Automatically purge messages" name="autopurge", sub_cmd_name="add", sub_cmd_description="Automatically purge messages"
@ -78,12 +79,13 @@ class PurgeCog(Scale):
await ctx.send("Autopurge already exists.", ephemeral=True) await ctx.send("Autopurge already exists.", ephemeral=True)
return return
_ = Autopurge( p = Autopurge(
guild=ctx.guild.id, guild=ctx.guild.id,
channel=channel.id, channel=channel.id,
admin=ctx.author.id, admin=ctx.author.id,
delay=delay, delay=delay,
).save() )
await p.commit()
await ctx.send(f"Autopurge set up on {channel.mention}, delay is {delay} seconds") await ctx.send(f"Autopurge set up on {channel.mention}, delay is {delay} seconds")
@ -98,11 +100,11 @@ class PurgeCog(Scale):
) )
@check(admin_or_permissions(Permissions.MANAGE_MESSAGES)) @check(admin_or_permissions(Permissions.MANAGE_MESSAGES))
async def _autopurge_remove(self, ctx: InteractionContext, channel: GuildText) -> None: async def _autopurge_remove(self, ctx: InteractionContext, channel: GuildText) -> None:
autopurge = Autopurge.objects(guild=ctx.guild.id, channel=channel.id) autopurge = await Autopurge.find_one(q(guild=ctx.guild.id, channel=channel.id))
if not autopurge: if not autopurge:
await ctx.send("Autopurge does not exist.", ephemeral=True) await ctx.send("Autopurge does not exist.", ephemeral=True)
return return
autopurge.delete() await autopurge.delete()
await ctx.send(f"Autopurge removed from {channel.mention}.") await ctx.send(f"Autopurge removed from {channel.mention}.")
@slash_command( @slash_command(
@ -126,12 +128,12 @@ class PurgeCog(Scale):
async def _autopurge_update( async def _autopurge_update(
self, ctx: InteractionContext, channel: GuildText, delay: int self, ctx: InteractionContext, channel: GuildText, delay: int
) -> None: ) -> None:
autopurge = Autopurge.objects(guild=ctx.guild.id, channel=channel.id) autopurge = await Autopurge.find_one(q(guild=ctx.guild.id, channel=channel.id))
if not autopurge: if not autopurge:
await ctx.send("Autopurge does not exist.", ephemeral=True) await ctx.send("Autopurge does not exist.", ephemeral=True)
return return
autopurge.delay = delay autopurge.delay = delay
autopurge.save() await autopurge.commit()
await ctx.send(f"Autopurge delay updated to {delay} seconds on {channel.mention}.") await ctx.send(f"Autopurge delay updated to {delay} seconds on {channel.mention}.")

View file

@ -6,6 +6,7 @@ from typing import List
from bson import ObjectId from bson import ObjectId
from dis_snek import InteractionContext, Snake from dis_snek import InteractionContext, Snake
from dis_snek.client.utils.misc_utils import get
from dis_snek.models.discord.channel import GuildChannel from dis_snek.models.discord.channel import GuildChannel
from dis_snek.models.discord.components import ActionRow, Select, SelectOption from dis_snek.models.discord.components import ActionRow, Select, SelectOption
from dis_snek.models.discord.embed import Embed, EmbedField from dis_snek.models.discord.embed import Embed, EmbedField
@ -15,8 +16,9 @@ from dis_snek.models.snek.application_commands import (
slash_command, slash_command,
slash_option, slash_option,
) )
from jarvis_core.db import q
from jarvis_core.db.models import Reminder
from jarvis.db.models import Reminder
from jarvis.utils import build_embed from jarvis.utils import build_embed
from jarvis.utils.cachecog import CacheCog from jarvis.utils.cachecog import CacheCog
@ -94,7 +96,7 @@ class RemindmeCog(CacheCog):
await ctx.send("At least one time period is required", ephemeral=True) await ctx.send("At least one time period is required", ephemeral=True)
return return
reminders = Reminder.objects(user=ctx.author.id, active=True).count() reminders = len(await Reminder.find(q(user=ctx.author.id, active=True)))
if reminders >= 5: if reminders >= 5:
await ctx.send( await ctx.send(
"You already have 5 (or more) active reminders. " "You already have 5 (or more) active reminders. "
@ -105,7 +107,7 @@ class RemindmeCog(CacheCog):
remind_at = datetime.now() + timedelta(**delta) remind_at = datetime.now() + timedelta(**delta)
_ = Reminder( r = Reminder(
user=ctx.author_id, user=ctx.author_id,
channel=ctx.channel.id, channel=ctx.channel.id,
guild=ctx.guild.id, guild=ctx.guild.id,
@ -113,7 +115,9 @@ class RemindmeCog(CacheCog):
remind_at=remind_at, remind_at=remind_at,
private=private, private=private,
active=True, active=True,
).save() )
await r.commit()
embed = build_embed( embed = build_embed(
title="Reminder Set", title="Reminder Set",
@ -183,7 +187,7 @@ class RemindmeCog(CacheCog):
ephemeral=True, ephemeral=True,
) )
return return
reminders = Reminder.objects(user=ctx.author.id, active=True) reminders = await Reminder.find(q(user=ctx.author.id, active=True))
if not reminders: if not reminders:
await ctx.send("You have no reminders set.", ephemeral=True) await ctx.send("You have no reminders set.", ephemeral=True)
return return
@ -194,7 +198,7 @@ class RemindmeCog(CacheCog):
@slash_command(name="reminders", sub_cmd_name="delete", sub_cmd_description="Delete a reminder") @slash_command(name="reminders", sub_cmd_name="delete", sub_cmd_description="Delete a reminder")
async def _delete(self, ctx: InteractionContext) -> None: async def _delete(self, ctx: InteractionContext) -> None:
reminders = Reminder.objects(user=ctx.author.id, active=True) reminders = await Reminder.find(q(user=ctx.author.id, active=True))
if not reminders: if not reminders:
await ctx.send("You have no reminders set", ephemeral=True) await ctx.send("You have no reminders set", ephemeral=True)
return return
@ -230,15 +234,10 @@ class RemindmeCog(CacheCog):
messages=message, messages=message,
timeout=60 * 5, timeout=60 * 5,
) )
for to_delete in context.context.values:
_ = Reminder.objects(user=ctx.author.id, id=ObjectId(to_delete)).delete()
for row in components:
for component in row.components:
component.disabled = True
fields = [] fields = []
for reminder in filter(lambda x: str(x.id) in context.context.values, reminders): for to_delete in context.context.values:
reminder = get(reminders, user=ctx.author.id, id=ObjectId(to_delete))
if reminder.private and isinstance(ctx.channel, GuildChannel): if reminder.private and isinstance(ctx.channel, GuildChannel):
fields.append( fields.append(
EmbedField( EmbedField(
@ -255,6 +254,12 @@ class RemindmeCog(CacheCog):
inline=False, inline=False,
) )
) )
await reminder.delete()
for row in components:
for component in row.components:
component.disabled = True
embed = build_embed( embed = build_embed(
title="Deleted Reminder(s)", title="Deleted Reminder(s)",
description="", description="",

View file

@ -1,6 +1,7 @@
"""Load the config for J.A.R.V.I.S.""" """Load the config for J.A.R.V.I.S."""
import os import os
from jarvis_core.config import Config as CConfig
from pymongo import MongoClient from pymongo import MongoClient
from yaml import load from yaml import load
@ -10,6 +11,19 @@ except ImportError:
from yaml import Loader from yaml import Loader
class JarvisConfig(CConfig):
REQUIRED = ["token", "client_id", "mongo", "urls"]
OPTIONAL = {
"sync": False,
"log_level": "WARNING",
"scales": None,
"events": True,
"gitlab_token": None,
"max_messages": 1000,
"twitter": None,
}
class Config(object): class Config(object):
"""Config singleton object for J.A.R.V.I.S.""" """Config singleton object for J.A.R.V.I.S."""

View file

@ -1,8 +1,8 @@
"""J.A.R.V.I.S. reminder background task handler.""" """J.A.R.V.I.S. reminder background task handler."""
from datetime import datetime, timedelta from datetime import datetime, timedelta
from dis_snek.ext.tasks.task import Task from dis_snek.models.snek.tasks.task import Task
from dis_snek.ext.tasks.triggers import IntervalTrigger from dis_snek.models.snek.tasks.triggers import IntervalTrigger
from jarvis_core.db import q from jarvis_core.db import q
from jarvis_core.db.models import Reminder from jarvis_core.db.models import Reminder

View file

@ -3,8 +3,8 @@ import logging
from datetime import datetime, timedelta from datetime import datetime, timedelta
import tweepy import tweepy
from dis_snek.ext.tasks.task import Task from dis_snek.models.snek.tasks.task import Task
from dis_snek.ext.tasks.triggers import IntervalTrigger from dis_snek.models.snek.tasks.triggers import IntervalTrigger
from jarvis_core.db import q from jarvis_core.db import q
from jarvis_core.db.models import Twitter from jarvis_core.db.models import Twitter
@ -41,7 +41,7 @@ async def tweets() -> None:
channel_id = twitter.channel channel_id = twitter.channel
tweets = sorted(tweets, key=lambda x: x.id) tweets = sorted(tweets, key=lambda x: x.id)
if guild_id not in guild_cache: if guild_id not in guild_cache:
guild_cache[guild_id] = await jarvis.jarvis.get_guild(guild_id) guild_cache[guild_id] = await jarvis.jarvis.fetch_guild(guild_id)
guild = guild_cache[twitter.guild] guild = guild_cache[twitter.guild]
if channel_id not in channel_cache: if channel_id not in channel_cache:
channel_cache[channel_id] = await guild.fetch_channel(channel_id) channel_cache[channel_id] = await guild.fetch_channel(channel_id)

View file

@ -1,8 +1,8 @@
"""J.A.R.V.I.S. unban background task handler.""" """J.A.R.V.I.S. unban background task handler."""
from datetime import datetime, timedelta from datetime import datetime, timedelta
from dis_snek.ext.tasks.task import Task from dis_snek.models.snek.tasks.task import Task
from dis_snek.ext.tasks.triggers import IntervalTrigger from dis_snek.models.snek.tasks.triggers import IntervalTrigger
from jarvis_core.db import q from jarvis_core.db import q
from jarvis_core.db.models import Ban, Unban from jarvis_core.db.models import Ban, Unban
@ -16,8 +16,8 @@ async def _unban() -> None:
bans = Ban.find(q(type="temp", active=True)) bans = Ban.find(q(type="temp", active=True))
async for ban in bans: async for ban in bans:
if ban.created_at + timedelta(hours=ban.duration) < datetime.now() + timedelta(minutes=10): if ban.created_at + timedelta(hours=ban.duration) < datetime.now() + timedelta(minutes=10):
guild = await jarvis.jarvis.get_guild(ban.guild) guild = await jarvis.jarvis.fetch_guild(ban.guild)
user = await jarvis.jarvis.get_user(ban.user) user = await jarvis.jarvis.fetch_user(ban.user)
if user: if user:
await guild.unban(user=user, reason="Ban expired") await guild.unban(user=user, reason="Ban expired")
ban.update(q(active=False)) ban.update(q(active=False))

View file

@ -2,8 +2,8 @@
from asyncio import to_thread from asyncio import to_thread
from datetime import datetime, timedelta from datetime import datetime, timedelta
from dis_snek.ext.tasks.task import Task from dis_snek.models.snek.tasks.task import Task
from dis_snek.ext.tasks.triggers import IntervalTrigger from dis_snek.models.snek.tasks.triggers import IntervalTrigger
import jarvis import jarvis
from jarvis.db.models import Lock from jarvis.db.models import Lock
@ -17,8 +17,8 @@ async def _unlock() -> None:
if False: if False:
for lock in locks: for lock in locks:
if lock.created_at + timedelta(minutes=lock.duration) < datetime.utcnow(): if lock.created_at + timedelta(minutes=lock.duration) < datetime.utcnow():
guild = await jarvis.jarvis.get_guild(lock.guild) guild = await jarvis.jarvis.fetch_guild(lock.guild)
channel = await jarvis.jarvis.get_guild(lock.channel) channel = await guild.fetch_channel(lock.channel)
if channel: if channel:
roles = await guild.fetch_roles() roles = await guild.fetch_roles()
for role in roles: for role in roles:

View file

@ -1,8 +1,8 @@
"""J.A.R.V.I.S. unwarn background task handler.""" """J.A.R.V.I.S. unwarn background task handler."""
from datetime import datetime, timedelta from datetime import datetime, timedelta
from dis_snek.ext.tasks.task import Task from dis_snek.models.snek.tasks.task import Task
from dis_snek.ext.tasks.triggers import IntervalTrigger from dis_snek.models.snek.tasks.triggers import IntervalTrigger
from jarvis_core.db import q from jarvis_core.db import q
from jarvis_core.db.models import Warning from jarvis_core.db.models import Warning