Skip to content

Instantly share code, notes, and snippets.

@larsenv
Last active August 17, 2023 17:18
Show Gist options
  • Save larsenv/bef589d754d05fcd24e19edfd0cc7964 to your computer and use it in GitHub Desktop.
Save larsenv/bef589d754d05fcd24e19edfd0cc7964 to your computer and use it in GitHub Desktop.
Use pisg with Discord! This script will take a Discord message log created with DiscordChatExporter and convert it into the "mbot" format so that it can be used to generate a webpage of statistics with pisg.
import datetime
import sys
messages = ""
if len(sys.argv) != 3:
print("Usage: dispisg.py <input> <output>")
sys.exit(1)
with open(sys.argv[1], "r") as f:
readlines = f.readlines()
i = 0
print("Parsing...")
print("\n")
for line in readlines:
try:
try:
parser = datetime.datetime.strftime(
datetime.datetime.strptime(
line[1:].split("]")[0], "%d/%m/%Y %I:%M %p"
),
"%a %b %d %H:%M:%S %Y",
)
except:
parser = datetime.datetime.strftime(
datetime.datetime.strptime(
line[1:].split("]")[0], "%d-%b-%y %I:%M %p"
),
"%a %b %d %H:%M:%S %Y",
)
parser += " " + "<" + line.split("] ")[1].replace("\n", "") + ">"
parser += " " + readlines[i + 1].replace("\n", "")
messages += parser + "\n"
except:
pass
i += 1
with open(sys.argv[2], "w") as f:
f.write(messages)
print("Saved messages!")
print("\n")
print("Run through pisg with this command.")
print("pisg -f mbot -o <output> -ch \#<channel name> -l " + sys.argv[2])
@hartlomiej
Copy link

still works in oct 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment