Skip to content

Replace all utcnow with just now #1302

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions techsupport_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ async def on_ready(self: Self) -> None:
"""Callback for when the bot is finished starting up.
This function may be called more than once and should not have discord interactions in it
"""
self.startup_time = datetime.datetime.utcnow()
self.startup_time = datetime.datetime.now()
await self.logger.send_log(
message="Bot online", level=LogLevel.INFO, console_only=True
)
Expand All @@ -242,7 +242,8 @@ async def log_DM(self: Self, sent_from: str, source: str, content: str) -> None:
embed = auxiliary.generate_basic_embed(
f"{source} recieved a PM", f"PM from: {sent_from}\n{content}"
)
embed.timestamp = datetime.datetime.utcnow()

embed.timestamp = datetime.datetime.now()
try:
await owner.send(embed=embed)
except discord.Forbidden as exception:
Expand Down Expand Up @@ -369,7 +370,7 @@ async def write_new_config(self: Self, guild_id: str, config: str) -> None:
).gino.first()
if database_config:
await database_config.update(
config=str(config), update_time=datetime.datetime.utcnow()
config=str(config), update_time=datetime.datetime.now()
).apply()
else:
new_database_config = self.models.Config(
Expand Down
4 changes: 2 additions & 2 deletions techsupport_bot/botlogging/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self: Self, message: str) -> None:
super().__init__(
title=self.title.upper(), description=message, color=self.color
)
self.timestamp = datetime.datetime.utcnow()
self.timestamp = datetime.datetime.now()

def modify_embed(self: Self, embed: discord.Embed) -> discord.Embed:
"""This modifies an existing embed to match with the LogEmbed style
Expand All @@ -41,7 +41,7 @@ def modify_embed(self: Self, embed: discord.Embed) -> discord.Embed:
embed.title = self.title
embed.color = self.color
embed.description = self.description
embed.timestamp = datetime.datetime.utcnow()
embed.timestamp = datetime.datetime.now()

return embed

Expand Down
2 changes: 1 addition & 1 deletion techsupport_bot/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async def patch_config(self: Self, ctx: commands.Context) -> None:

json_file = discord.File(
io.StringIO(json.dumps(json_config, indent=4)),
filename=f"{ctx.guild.id}-config-{datetime.datetime.utcnow()}.json",
filename=f"{ctx.guild.id}-config-{datetime.datetime.now()}.json",
)

await ctx.send(file=json_file)
Expand Down
6 changes: 2 additions & 4 deletions techsupport_bot/commands/factoids.py
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ async def _json(self: Self, ctx: commands.Context, factoid_name: str) -> None:
json_file = discord.File(
io.StringIO(formatted),
filename=(
f"{aliases_list[0]}-factoid-embed-config-{datetime.datetime.utcnow()}.json"
f"{aliases_list[0]}-factoid-embed-config-{datetime.datetime.now()}.json"
),
)

Expand Down Expand Up @@ -2003,9 +2003,7 @@ async def send_factoids_as_file(

yaml_file = discord.File(
io.StringIO(yaml.dump(output_data)),
filename=(
f"factoids-for-server-{guild.id}-{datetime.datetime.utcnow()}.yaml"
),
filename=(f"factoids-for-server-{guild.id}-{datetime.datetime.now()}.yaml"),
)

# Returns the file
Expand Down
2 changes: 1 addition & 1 deletion techsupport_bot/commands/hangman.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def __init__(self: Self, word: str, max_guesses: int = 6) -> None:
self.guesses = set()
self.step = 0
self.max_guesses = max_guesses
self.started = datetime.datetime.utcnow()
self.started = datetime.datetime.now()
self.id = uuid.uuid4()

def draw_word_state(self: Self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion techsupport_bot/commands/listen.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def format_message_in_embed(self: Self, message: discord.Message) -> discord.Emb
"""
embed = auxiliary.generate_basic_embed(description=message.clean_content)

embed.timestamp = datetime.datetime.utcnow()
embed.timestamp = datetime.datetime.now()
embed.set_author(
name=message.author.name, icon_url=message.author.display_avatar.url
)
Expand Down
2 changes: 1 addition & 1 deletion techsupport_bot/commands/members.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async def get_members_with_role(
yaml_file = discord.File(
io.StringIO(yaml.dump(yaml_output_data)),
filename=f"members-with-{role.name}-in"
+ f"-{ctx.guild.id}-{datetime.datetime.utcnow()}.yaml",
+ f"-{ctx.guild.id}-{datetime.datetime.now()}.yaml",
)

await ctx.send(file=yaml_file)
Expand Down
20 changes: 10 additions & 10 deletions techsupport_bot/commands/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async def on_message_edit(
title="Message edit",
description=f"Message ID: {before.id}",
)
embed.timestamp = datetime.utcnow()
embed.timestamp = datetime.now()

# This is here to save space if this listener is triggered by something other than
# a content modification, i.e. a message being pinned
Expand Down Expand Up @@ -317,7 +317,7 @@ async def handle_dm(message: discord.Message) -> None:

embed = discord.Embed(color=discord.Color.blue(), description=message.content)
embed.set_footer(text=f"Message ID: {message.id}")
embed.timestamp = datetime.utcnow()
embed.timestamp = datetime.now()
if message.author.avatar:
embed.set_author(name=message.author, icon_url=message.author.avatar.url)
else:
Expand Down Expand Up @@ -493,7 +493,7 @@ async def create_thread(
# has to be done like this because of member handling
embed.description = description
embed.set_author(name=user, icon_url=url)
embed.timestamp = datetime.utcnow()
embed.timestamp = datetime.now()
embed.set_footer(text=f"User ID: {user.id}")

# Handling for roles to ping, not performed if the func was invoked by the contact command
Expand Down Expand Up @@ -521,7 +521,7 @@ async def create_thread(
embed = discord.Embed(color=discord.Color.blue(), description=message.content)
embed.set_author(name=user, icon_url=url)
embed.set_footer(text=f"Message ID: {message.id}")
embed.timestamp = datetime.utcnow()
embed.timestamp = datetime.now()

attachments = None
if message.attachments:
Expand All @@ -539,7 +539,7 @@ async def create_thread(
)
embed.set_author(name="Thread Created")
embed.set_footer(text="Your message has been sent.")
embed.timestamp = datetime.utcnow()
embed.timestamp = datetime.now()

await message.author.send(embed=embed)

Expand Down Expand Up @@ -632,7 +632,7 @@ async def reply_to_thread(
# No need to reconfirm
user_attachments = await build_attachments(thread=thread, message=message)

embed.timestamp = datetime.utcnow()
embed.timestamp = datetime.now()
embed.set_footer(text="Response")

if automatic:
Expand Down Expand Up @@ -699,7 +699,7 @@ async def close_thread(
embed.set_footer(
text="Closing will be cancelled if a message is sent, or if the command is run again."
)
embed.timestamp = datetime.utcnow()
embed.timestamp = datetime.now()

await thread.send(embed=embed)

Expand Down Expand Up @@ -764,7 +764,7 @@ async def close_thread(
description="Please wait 24 hours before creating a new one.",
)
embed.set_author(name="Thread Closed")
embed.timestamp = datetime.utcnow()
embed.timestamp = datetime.now()

await user.send(embed=embed)

Expand Down Expand Up @@ -811,7 +811,7 @@ async def log_closure(
icon_url=closed_by.avatar.url,
text=f"Thread closed by {closed_by.name}",
)
embed.timestamp = datetime.utcnow()
embed.timestamp = datetime.now()

await log_channel.send(embed=embed)

Expand Down Expand Up @@ -1341,7 +1341,7 @@ async def modmail_commands(self: Self, ctx: commands.Context) -> None:
description=f"*You can use these by typing `{prefix}<command>` in a modmail thread*",
title="Modmail commands",
)
embed.timestamp = datetime.utcnow()
embed.timestamp = datetime.now()

# First three are reply commands
for command in list_of_modmail_commands[:3]:
Expand Down
2 changes: 1 addition & 1 deletion techsupport_bot/commands/protect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ async def purge_duration(
)
return

timestamp = datetime.datetime.utcnow() - datetime.timedelta(
timestamp = datetime.datetime.now() - datetime.timedelta(
minutes=duration_minutes
)

Expand Down
2 changes: 1 addition & 1 deletion techsupport_bot/commands/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ async def edit_rules(self: Self, ctx: commands.Context) -> None:

json_file = discord.File(
io.StringIO(json.dumps(rules_data, indent=4)),
filename=f"{ctx.guild.id}-rules-{datetime.datetime.utcnow()}.json",
filename=f"{ctx.guild.id}-rules-{datetime.datetime.now()}.json",
)

await ctx.send(content="Re-upload this file to apply new rules", file=json_file)
Expand Down
2 changes: 1 addition & 1 deletion techsupport_bot/commands/voting.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ async def execute(self: Self, config: munch.Munch, guild: discord.Guild) -> None
)
for vote in active_votes:
end_time = int((vote.start_time + timedelta(hours=72)).timestamp())
if end_time <= int(datetime.datetime.utcnow().timestamp()):
if end_time <= int(datetime.datetime.now().timestamp()):
await self.end_vote(vote, guild)

async def end_vote(self: Self, vote: munch.Munch, guild: discord.Guild) -> None:
Expand Down
2 changes: 1 addition & 1 deletion techsupport_bot/commands/who.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ async def all_notes(

yaml_file = discord.File(
io.StringIO(yaml.dump({"notes": note_output_data})),
filename=f"notes-for-{user.id}-{datetime.datetime.utcnow()}.yaml",
filename=f"notes-for-{user.id}-{datetime.datetime.now()}.yaml",
)

await interaction.response.send_message(file=yaml_file, ephemeral=True)
Expand Down
16 changes: 8 additions & 8 deletions techsupport_bot/core/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Applications(bot.db.Model):
background: str = bot.db.Column(bot.db.String)
reason: str = bot.db.Column(bot.db.String)
application_time: datetime.datetime = bot.db.Column(
bot.db.DateTime, default=datetime.datetime.utcnow
bot.db.DateTime, default=datetime.datetime.now
)

class ApplicationBans(bot.db.Model):
Expand Down Expand Up @@ -85,7 +85,7 @@ class DuckUser(bot.db.Model):
befriend_count: int = bot.db.Column(bot.db.Integer, default=0)
kill_count: int = bot.db.Column(bot.db.Integer, default=0)
updated: datetime.datetime = bot.db.Column(
bot.db.DateTime, default=datetime.datetime.utcnow
bot.db.DateTime, default=datetime.datetime.now
)
speed_record: float = bot.db.Column(bot.db.Float, default=80.0)

Expand Down Expand Up @@ -114,7 +114,7 @@ class Factoid(bot.db.Model):
guild: str = bot.db.Column(bot.db.String)
message: str = bot.db.Column(bot.db.String)
time: datetime.datetime = bot.db.Column(
bot.db.DateTime, default=datetime.datetime.utcnow
bot.db.DateTime, default=datetime.datetime.now
)
embed_config: str = bot.db.Column(bot.db.String, default=None)
hidden: bool = bot.db.Column(bot.db.Boolean, default=False)
Expand Down Expand Up @@ -165,7 +165,7 @@ class Grab(bot.db.Model):
guild: str = bot.db.Column(bot.db.String)
message: str = bot.db.Column(bot.db.String)
time: datetime.datetime = bot.db.Column(
bot.db.DateTime, default=datetime.datetime.utcnow
bot.db.DateTime, default=datetime.datetime.now
)
nsfw: bool = bot.db.Column(bot.db.Boolean, default=False)

Expand Down Expand Up @@ -218,7 +218,7 @@ class UserNote(bot.db.Model):
user_id: str = bot.db.Column(bot.db.String)
guild_id: str = bot.db.Column(bot.db.String)
updated: datetime.datetime = bot.db.Column(
bot.db.DateTime, default=datetime.datetime.utcnow
bot.db.DateTime, default=datetime.datetime.now
)
author_id: str = bot.db.Column(bot.db.String)
body: str = bot.db.Column(bot.db.String)
Expand All @@ -242,7 +242,7 @@ class Warning(bot.db.Model):
guild_id: str = bot.db.Column(bot.db.String)
reason: str = bot.db.Column(bot.db.String)
time: datetime.datetime = bot.db.Column(
bot.db.DateTime, default=datetime.datetime.utcnow
bot.db.DateTime, default=datetime.datetime.now
)

class Config(bot.db.Model):
Expand All @@ -262,7 +262,7 @@ class Config(bot.db.Model):
guild_id: str = bot.db.Column(bot.db.String)
config: str = bot.db.Column(bot.db.String)
update_time: datetime.datetime = bot.db.Column(
bot.db.DateTime, default=datetime.datetime.utcnow
bot.db.DateTime, default=datetime.datetime.now
)

class Listener(bot.db.Model):
Expand Down Expand Up @@ -335,7 +335,7 @@ class Votes(bot.db.Model):
votes_no: int = bot.db.Column(bot.db.Integer, default=0)
votes_total: int = bot.db.Column(bot.db.Integer, default=0)
start_time: datetime.datetime = bot.db.Column(
bot.db.DateTime, default=datetime.datetime.utcnow
bot.db.DateTime, default=datetime.datetime.now
)
vote_active: bool = bot.db.Column(bot.db.Boolean, default=True)
blind: bool = bot.db.Column(bot.db.Boolean, default=False)
Expand Down
2 changes: 1 addition & 1 deletion techsupport_bot/functions/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def build_embed(self: Self, ctx: commands.Context) -> discord.Embed:

# Set basic items
embed.color = discord.Color.greyple()
embed.timestamp = datetime.datetime.utcnow()
embed.timestamp = datetime.datetime.now()

# Add the message content
embed.title = "Content"
Expand Down