Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
release: 0.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexogamer committed May 7, 2022
1 parent 90a50fe commit 6c07f5c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.5.2 (2022-05-07)

- Optimise message fetcher.

# v0.5.1 (2022-05-07)

- Avoid ratelimiting.
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Revchiver

Archiving library for Revolt.

## Usage

Basic example - **make sure to pass Revolt.JS messages to the function**:

```ts
import { archiveChannel } from "revchiver/dist";

const msg = "<insert revolt.js message object here>";
const ignoredMsgs = ["array", "of", "message", "objects"];

const data = await archiveChannel(msg, ignoredMsgs);
```
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "revchiver",
"version": "0.5.1",
"version": "0.5.2",
"description": "Archiving library for Revolt.",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down
37 changes: 19 additions & 18 deletions src/archiveChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ async function archiveChannel(msg: Message, ignoredMsgs?: Message[]) {
archiveData.archived_at = msg.createdAt;

// fetch/push messages
function pushMsg(m: Message, users: Member[]) {
let sender;
for (const u of users!) {
if (m.author_id !== u.user?._id) continue;
sender = u;
}
function pushMsg(m: Message) {
// users?: Member[]
// let sender;
// for (const u of users!) {
// if (m.author_id !== u.user?._id) continue;
// sender = u;
// }

let attachmentsObj: string[] = [];
m.attachments?.forEach((a) => {
Expand All @@ -40,10 +41,11 @@ async function archiveChannel(msg: Message, ignoredMsgs?: Message[]) {
archiveData.messages.push({
message_id: m._id,
sender_id: m.author_id,
sender_name: m.masquerade?.name ?? sender?.nickname ?? m.author?.username, // order: masq > nick > username
sender_name:
m.masquerade?.name ?? m.member?.nickname ?? m.author?.username, // order: masq > nick > username
sender_avatar: `${autumnURL}/avatars/${
m.masquerade?.avatar ?? sender?.avatar
? `${sender?.avatar?._id}/${sender?.avatar?.filename}`
m.masquerade?.avatar ?? m.member?.avatar
? `${m.member?.avatar?._id}/${m.member?.avatar?.filename}`
: `${m.author?.avatar?._id}/${m.author?.avatar?.filename}`
}`, // order: masq > server > global
content: m.content ?? m.system,
Expand All @@ -53,25 +55,24 @@ async function archiveChannel(msg: Message, ignoredMsgs?: Message[]) {
let continueFetching = true;
let fetchbefore = msg._id;
while (continueFetching) {
const msgs = await msg.channel?.fetchMessagesWithUsers({
const msgs = await msg.channel?.fetchMessages({
limit: 100,
before: fetchbefore,
});
if (!msgs || !msgs.messages) return "nothingToArchive";
const users = msgs.members;
if (!msgs) return "nothingToArchive";

if (fetchbefore === msg._id) {
const extraMsg = await msg.channel?.fetchMessagesWithUsers({ limit: 1 });
pushMsg(extraMsg?.messages[0]!, extraMsg?.members!);
const extraMsg = await msg.channel?.fetchMessage(msg._id);
pushMsg(extraMsg!);
}
msgs.messages.forEach((m) => {
msgs.forEach((m) => {
if (!ignoredMsgs || !ignoredMsgs.includes(m)) {
pushMsg(m, users!);
pushMsg(m);
}
if (msgs.messages.length < 100) {
if (msgs.length < 100) {
continueFetching = false;
} else {
fetchbefore = msgs.messages[99]._id;
fetchbefore = msgs[99]._id;
}
});

Expand Down

0 comments on commit 6c07f5c

Please sign in to comment.