Skip to main content

A simple Discord chat exporter for Python Discord bots.

Project description

Version Language Forks Stargazers Issues GPL License

DiscordChatExporterPy-hikari

Export Discord chats with your hikari bots!


Installation

To install the library to your virtual environment, for bot usage, run the command:

pip install chat-exporter-hikari

To clone the repository locally, run the command:

git clone https://github.com/h4ckd0tm3/DiscordChatExporterPy-hikari

(back to top)


Usage

There are currently 3 methods (functions) to chat-exporter which you can use to export your chat.
Expand the blocks below to learn the functions, arguments and usages.

Basic Usage

.quick_export() is the simplest way of using chat-exporter.

Using the quick_export function will gather the history of the channel you give, build the transcript then post the file and embed directly to the channel - returning a message object gathered from the message it posted.

This is mostly seen as a demo function, as opposed to a command you should actually use.

Required Argument(s):
channel: hikari.channels.PartialChannel object, whether ctx.channel or any channel you gather.

Optional Argument(s):
bot: commands.Bot object to gather members who are no longer in your guild.

Return Argument:
hikari.messages.Message: The message quick_export will send, containing the embed and exported chat file.

Example:

import hikari
import lightbulb
import chat_exporter


bot = lightbulb.BotApp(token="...")

...

@bot.command
@lightbulb.command("save", "Saves current chat transcript.")
@lightbulb.implements(lightbulb.SlashCommand)
async def save(ctx):
    await chat_exporter.quick_export(ctx.get_channel())
    await ctx.respond("Transcript created!")

...
Customisable Usage

.export() is the most efficient and flexible method to export a chat using chat-exporter.

Using the export function will generate a transcript using the channel you pass in, along with using any of the custom kwargs passed in to set limits, timezone, 24h formats and more (listed below).

This would be the main function to use within chat-exporter.

Required Argument(s):
channel: hikari.channels.PartialChannel object, whether ctx.channel or any channel you gather.

Optional Argument(s):
limit: Integer value to set the limit (amount of messages) the chat exporter gathers when grabbing the history (default=unlimited).
tz_info: String value of a TZ Database name to set a custom timezone for the exported messages (default=UTC)
military_time: Boolean value to set a 24h format for times within your exported chat (default=False | 12h format)
fancy_times: Boolean value which toggles the 'fancy times' (Today|Yesterday|Day)
bot: commands.Bot object to gather members who are no longer in your guild.

Return Argument:
transcript: The HTML build-up for you to construct the HTML File with Discord.

Example:

import io

...

@bot.command
@lightbulb.command("save", "Saves current chat transcript.")
@lightbulb.implements(lightbulb.SlashCommand)
async def save(ctx, limit: int = 100, tz_info: str = "UTC", military_time: bool = True):
    channel = ctx.get_channel()
    transcript = await chat_exporter.export(
        channel,
        limit=limit,
        tz_info=tz_info,
        military_time=military_time,
        bot=lightbulb.BotApp)

    if transcript is None:
        return

    transcript_file = hikari.files.Bytes(io.BytesIO(transcript.encode()), f"transcript-{channel.name}.html")

    await ctx.respond(transcript_file)
Raw Usage

.raw_export() is for the crazy people who like to do their own thing when using chat-exporter.

Using the raw_export function will generate a transcript using the list of messages you pass in, along with using any of the custom kwargs passed in to set limits, timezone, 24h formats and more (listed below).

This would be for people who want to filter what content to export.

Required Argument(s):
channel: hikari.channels.PartialChannel object, whether ctx.channel or any channel you gather (this is just for padding the header).
messages: A list of Message objects which you wish to export to an HTML file.

Optional Argument(s):
tz_info: String value of a TZ Database name to set a custom timezone for the exported messages (default=UTC)
military_time: Boolean value to set a 24h format for times within your exported chat (default=False | 12h format)
fancy_times: Boolean value which toggles the 'fancy times' (Today|Yesterday|Day)
bot: commands.Bot object to gather members who are no longer in your guild.

Return Argument:
transcript: The HTML build-up for you to construct the HTML File with Discord.

Example:

import io

...

@bot.command
@lightbulb.command("save", "Saves current chat transcript.")
@lightbulb.implements(lightbulb.SlashCommand)
async def save(ctx, tz_info: str = "UTC", military_time: bool = True):
    channel = ctx.get_channel()
    
    messages = ...
    
    transcript = await chat_exporter.raw_export(
        channel,
        messages=messages,
        tz_info=tz_info,
        military_time=military_time,
        bot=lightbulb.BotApp)

    if transcript is None:
        return

    transcript_file = hikari.files.Bytes(io.BytesIO(transcript.encode()), f"transcript-{channel.name}.html")

    await ctx.respond(transcript_file)

(back to top)


Screenshots

General
    Discord
    Chat-Exporter

(back to top)


Additional Functions

Link Function Downloading exported chats can build up a bunch of unwanted files on your PC which can get annoying, additionally - not everyone wants to download content from Discord.

Due to these pain, and many requests - I have built a fancy PHP script which will show the transcript file within a browser.

    quick_link Similar in design to `.quick_export()` this is a bit of a demo function to produce a link and to give you an embed.

    Required Argument(s):
    channel: hikari.channels.PartialChannel object, whether ctx.channel or any channel you gather.
    message: The Discord message containing the transcript file

    Return Argument:
    hikari.messages.Message: The message quick_link will send, containing the embed.

    Example:

    import chat_exporter
    
    ...
    
    @bot.command()
    async def save(ctx: commands.Context):
        message = await chat_exporter.quick_export(ctx.channel)
        await chat_exporter.quick_link(ctx.channel, message)
    
    link A simple function to return the link you will need to view the transcript online.

    Required Argument(s):
    message: The Discord message containing the transcript file

    Return Argument:
    link: The link to view the transcript file online

    Example:

    import io
    
    import chat_exporter
    
    ...
    
    @bot.command()
    async def save(ctx: commands.Context):
        transcript = await chat_exporter.export(ctx.channel)
        
        if transcript is None:
            return
    
        transcript_file = discord.File(
            io.BytesIO(transcript.encode()),
            filename=f"transcript-{ctx.channel.name}.html",
        )
    
        message = await ctx.send(file=transcript_file)
        link = await chat_exporter.link(message)
    
        await ctx.send("Click this link to view the transcript online: " + link)
    

Please note that the PHP script does NOT store any information.
It simply makes a request to the given URL and echos (prints) the content for you to be able to view it.


Attributions

This project borrows CSS and HTML code from Tyrrrz's C# DiscordChatExporter repository.

This project is based on DiscordChatExporterPy, the work of mahtoid.

(back to top)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chat_exporter_hikari-1.0.1.tar.gz (47.7 kB view details)

Uploaded Source

Built Distribution

chat_exporter_hikari-1.0.1-py3-none-any.whl (58.9 kB view details)

Uploaded Python 3

File details

Details for the file chat_exporter_hikari-1.0.1.tar.gz.

File metadata

  • Download URL: chat_exporter_hikari-1.0.1.tar.gz
  • Upload date:
  • Size: 47.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.1

File hashes

Hashes for chat_exporter_hikari-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b14dfd8886748b71c19f81017d9f2f3cbd2078734fd4f24c9120059f50891a22
MD5 5faaaa864fd23249950867f3b44a6066
BLAKE2b-256 26aaf0c80f672de5fb1bd85e5ab883716cec1af5ca69f397344b7e027cb055de

See more details on using hashes here.

File details

Details for the file chat_exporter_hikari-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for chat_exporter_hikari-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9657cbe592ced7e1d867f7aea625c83693689a960545403bc10b5d1a68c60096
MD5 9d85c83803772b8d57de727c8f62ec03
BLAKE2b-256 021fd7adf107f0f1020843a6e6b8c05a9eeef04cca2d2fbaf308b6b7577f0b45

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page