Skip to content

Commit

Permalink
Made bulk message csvs tempurary and removed some prints from weather
Browse files Browse the repository at this point in the history
  • Loading branch information
SkillpTm committed Aug 16, 2022
1 parent 2cb2e7f commit 6643986
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
7 changes: 5 additions & 2 deletions cogs/logs/external_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import nextcord
from nextcord import Color
from nextcord.ext import commands
import os

client = commands.Bot(intents=nextcord.Intents.all())

Expand Down Expand Up @@ -98,15 +99,17 @@ async def on_bulk_message_delete(self,
author_icon = member_avatar_url,

field_one_name = "External purge:",
field_one_value = f"{entry.user.mention} purged: `{len(messages)} message(s)` in {entry.target.mention}without using {self.client.user.mention}",
field_one_value = f"{entry.user.mention} purged: `{len(messages)} message(s)` in {entry.target.mention} without using {self.client.user.mention}",
field_one_inline = False,

field_two_name = "Note:",
field_two_value = "It is possible that there is no CSV after this message or that messages are missing. This is due to the messages not being cached anymore. In this case there is nothing I can do.",
field_two_inline = False)

await AUDIT_LOG.send(embed=embed)
await AUDIT_LOG.send(file=nextcord.File("./storage/bulk_messages.csv"))
await AUDIT_LOG.send(file=nextcord.File("./storage/temp/bulk_messages.csv"))

os.remove("./storage/temp/bulk_messages.csv")

###on#member#kick###########################################################

Expand Down
5 changes: 4 additions & 1 deletion cogs/mod_commands/purge.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import nextcord
from nextcord import Color, Interaction, SlashOption
from nextcord.ext import application_checks, commands
import os

client = commands.Bot(intents=nextcord.Intents.all())

Expand Down Expand Up @@ -55,7 +56,9 @@ async def purge(self,
field_two_inline = False)

await AUDIT_LOG.send(embed=embed)
await AUDIT_LOG.send(file=nextcord.File("./storage/bulk_messages.csv"))
await AUDIT_LOG.send(file=nextcord.File("./storage/temp/bulk_messages.csv"))

os.remove("./storage/temp/bulk_messages.csv")

uses_update("mod_command_uses", "purge")

Expand Down
13 changes: 5 additions & 8 deletions cogs/weather/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, client):
async def weather(self,
interaction: Interaction,
*,
location: str = SlashOption(description="The artist you want a song to see the lyrics of", required=True, min_length=1, max_length=30)):
location: str = SlashOption(description="the location you want to know thw weather of", required=True, min_length=1, max_length=30)):
if not checks(interaction):
return

Expand All @@ -44,13 +44,13 @@ async def weather(self,

API_KEY = os.getenv("WEATHER_API_KEY")

request_url_old = f"http://api.openweathermap.org/data/2.5/weather?appid={API_KEY}&q={location}&units=metric"
request_url = f"http://api.openweathermap.org/data/2.5/weather?appid={API_KEY}&q={location}&units=metric"

if not requests.get(request_url_old).status_code == 200:
if not requests.get(request_url).status_code == 200:
await interaction.response.send_message("Your selected location couldn't be found.", ephemeral=True)
return

weather_data = requests.get(request_url_old).json()
weather_data = requests.get(request_url).json()

descirption = weather_data["weather"][0]["description"]
humidity = weather_data["main"]["humidity"]
Expand All @@ -69,11 +69,8 @@ async def weather(self,
country = pycountry.countries.get(alpha_2=country_code)

format = "%Y/%m/%d %H:%M:%S"
print(location_time_utc, timezone_difference)
unformated_time = datetime.datetime.fromtimestamp(location_time_utc + timezone_difference - 7200)
print(unformated_time)
unformated_time = datetime.datetime.fromtimestamp(location_time_utc + timezone_difference - 7200) #For some reason all times are 2h off, this fixes it
local_date_and_time = unformated_time.strftime(format)
print(local_date_and_time)
local_date_and_time = local_date_and_time.split(" ")

output = f"""
Expand Down
4 changes: 2 additions & 2 deletions utilities/partial_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,13 @@ def make_bulk_messages_csv(messages):
messages.reverse()
format = "%Y/%m/%d %H:%M:%S"

with open('./storage/bulk_messages.csv', 'w') as file:
with open('./storage/temp/bulk_messages.csv', 'w') as file:
write = csv.writer(file)

write.writerow(["Author ID", "Author Name", "Send at", "Content"])

for i in range(len(messages)):
with open('./storage/bulk_messages.csv', 'a') as file:
with open('./storage/temp/bulk_messages.csv', 'a') as file:
write = csv.writer(file)
message_send_time = messages[i].created_at.strftime(format)

Expand Down

0 comments on commit 6643986

Please sign in to comment.