parent
0d7123b003
commit
6c9f7336ef
@ -0,0 +1,163 @@ |
||||
import { Client, Intents } from "discord.js"; |
||||
import assert from "assert"; |
||||
import { TOKEN } from "../secrets/discord.js"; |
||||
|
||||
const client = new Client({ |
||||
intents: [ |
||||
Intents.FLAGS.GUILDS, |
||||
Intents.FLAGS.GUILD_MEMBERS, |
||||
Intents.FLAGS.GUILD_MESSAGES, |
||||
Intents.FLAGS.GUILD_MESSAGE_REACTIONS, |
||||
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS, |
||||
Intents.FLAGS.GUILD_INVITES, |
||||
Intents.FLAGS.DIRECT_MESSAGES |
||||
], |
||||
partials: [ "REACTION", "MESSAGE", "CHANNEL", "GUILD_MEMBER" ], |
||||
allowedMentions: { |
||||
parse: ["users", "roles", "everyone"], |
||||
repliedUser: true |
||||
} |
||||
}); |
||||
|
||||
const load_guild_channel = async (client) => { |
||||
const guilds = await client.guilds.fetch(); |
||||
|
||||
let temp = guilds.entries().next().value[1]; |
||||
assert(temp, "Can't find any guilds/servers."); |
||||
|
||||
const guild = await temp.fetch(); |
||||
assert(guild, "No guild after fetch."); |
||||
|
||||
const channels = await guild.channels.fetch(); |
||||
|
||||
for(let chan of channels.entries()) { |
||||
if(chan[1].type === "GUILD_TEXT") { |
||||
// remember, return await puts the errors here
|
||||
return [guild, await chan[1].fetch()]; |
||||
} |
||||
} |
||||
|
||||
// fallthrough, no text channels
|
||||
return [guild, undefined]; |
||||
} |
||||
|
||||
client.login(TOKEN); |
||||
|
||||
let [guild, channel] = await load_guild_channel(client); |
||||
assert(channel !== undefined, "Did not find one text channel."); |
||||
|
||||
console.log("Connected to Sever/Guild", guild.name); |
||||
console.log("Sending invites from Channel", channel.name); |
||||
|
||||
const create_invite = async (channel) => { |
||||
return await channel.createInvite({ |
||||
maxAge: 120, maxUses: 1, unique: true |
||||
}); |
||||
} |
||||
|
||||
client.on("ready", async () => { |
||||
console.log("Ready."); |
||||
}); |
||||
|
||||
|
||||
const all_events = [ |
||||
"apiRequest", |
||||
"apiResponse", |
||||
"channelCreate", |
||||
"channelDelete", |
||||
"channelPinsUpdate", |
||||
"channelUpdate", |
||||
"debug", |
||||
"emojiCreate", |
||||
"emojiDelete", |
||||
"emojiUpdate", |
||||
"error", |
||||
"guildBanAdd", |
||||
"guildBanRemove", |
||||
"guildCreate", |
||||
"guildDelete", |
||||
"guildIntegrationsUpdate", |
||||
"guildMemberAdd", |
||||
"guildMemberAvailable", |
||||
"guildMemberRemove", |
||||
"guildMembersChunk", |
||||
"guildMemberUpdate", |
||||
"guildScheduledEventCreate", |
||||
"guildScheduledEventDelete", |
||||
"guildScheduledEventUpdate", |
||||
"guildScheduledEventUserAdd", |
||||
"guildScheduledEventUserRemove", |
||||
"guildUnavailable", |
||||
"guildUpdate", |
||||
"interactionCreate", |
||||
"invalidated", |
||||
"invalidRequestWarning", |
||||
"inviteCreate", |
||||
"inviteDelete", |
||||
"messageDelete", |
||||
"messageDeleteBulk", |
||||
"messageReactionAdd", |
||||
"messageReactionRemove", |
||||
"messageReactionRemoveAll", |
||||
"messageReactionRemoveEmoji", |
||||
"messageUpdate", |
||||
"presenceUpdate", |
||||
"rateLimit", |
||||
"roleCreate", |
||||
"roleDelete", |
||||
"roleUpdate", |
||||
"shardDisconnect", |
||||
"shardError", |
||||
"shardReady", |
||||
"shardReconnecting", |
||||
"shardResume", |
||||
"stageInstanceCreate", |
||||
"stageInstanceDelete", |
||||
"stageInstanceUpdate", |
||||
"stickerCreate", |
||||
"stickerDelete", |
||||
"stickerUpdate", |
||||
"threadCreate", |
||||
"threadDelete", |
||||
"threadListSync", |
||||
"threadMembersUpdate", |
||||
"threadMemberUpdate", |
||||
"threadUpdate", |
||||
"typingStart", |
||||
"userUpdate", |
||||
"voiceStateUpdate", |
||||
"warn", |
||||
"webhookUpdate", |
||||
]; |
||||
|
||||
|
||||
client.on('interactionCreate', interaction => { |
||||
console.log("INTERACTION", interaction); |
||||
}); |
||||
|
||||
const BAN_LIST = {"zedshaw": true}; |
||||
|
||||
client.on("messageCreate", async msg => { |
||||
if(msg.channel.type === "DM") { |
||||
console.log("DM FROM", msg.author.username, msg.channel.type, msg.channel.name, msg.content); |
||||
} else if(msg.channel.name === "livestream") { |
||||
console.log(">>> LIVESTREAM CHAT MESSAGE FROM", msg.author.username, msg.channel.type, msg.channel.name, msg.content); |
||||
|
||||
// banlist lookup user
|
||||
const is_ban = BAN_LIST[msg.author.username]; |
||||
if(is_ban) { |
||||
console.log("IGNORE BANNED USER", msg.author.username); |
||||
} else { |
||||
// else
|
||||
// socket_conn send message
|
||||
} |
||||
} else { |
||||
console.log("IGNORED MESSAGE FROM", msg.author.username, "IN", msg.channel.name); |
||||
} |
||||
}); |
||||
|
||||
for(let event of all_events) { |
||||
client.on(event, (args) => { |
||||
console.log("EVENT", event, "ARGS", args); |
||||
}); |
||||
} |
Loading…
Reference in new issue