Skip to content

Instantly share code, notes, and snippets.

@gaburipeach
Created January 6, 2023 20:19
Show Gist options
  • Save gaburipeach/a713e7358e114a6e4687f425f174d8d4 to your computer and use it in GitHub Desktop.
Save gaburipeach/a713e7358e114a6e4687f425f174d8d4 to your computer and use it in GitHub Desktop.
const KeybaseBot = require('keybase-bot');
const fs = require('fs');
async function main() {
// Create a new bot instance
const bot = new KeybaseBot();
/* now you can do things with the bot */
await bot.initFromRunningService()
/* now you can do things with the bot */
// await bot.deinit() // when done
const channels = await bot.chat.list({ filter: 'channel' });
let this_is_the_channel = null;
// Print the names of the channels.
channels.forEach((channel) => {
// console.log(channel);
// console.log(channel.channel.name);
if (channel.channel.name == 'uddhav,zlex7') {
this_is_the_channel = channel;
}
});
console.log(this_is_the_channel);
const limit = 1100;
// Set the starting point for pagination to the most recent message
let pagination = {
direction: 'backward',
num: limit,
};
// Load the chat with the specified name
// const chat = await bot.chat.read({name: INSERT_NAME_HERE}, pagination);
let messages = [];
let moreMessages = true;
while (moreMessages) {
// Retrieve the messages in the chat
const result = await bot.chat.read({name: 'uddhav,zlex7'}, pagination);
// Add the messages to the array
messages.push(result);
// Update the pagination cursor to the earliest message in the current batch
pagination = {
id: result[0].id,
direction: 'backward',
num: limit,
};
// Check if there are more messages to retrieve
moreMessages = result.length === limit;
}
// for (message of chat) {
// messages.push(message);
// }
var json = JSON.stringify(messages);
fs.writeFile('chat.json', json, (err) => {if (err) throw err;});
// Stop the bot
await bot.deinit();
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment