This commit is contained in:
mightypanders 2022-02-27 16:20:42 +01:00
parent 8f39a001e5
commit b8930ae74a
2 changed files with 20 additions and 62 deletions

View File

@ -1,5 +1,4 @@
import { REST } from '@discordjs/rest'
import { commands } from './constants'
import { Routes } from 'discord-api-types/v9'
import { config } from './configuration'
import { Client, Collection, CommandInteraction, GuildMember, GuildScheduledEvent, GuildScheduledEventManager, Intents, Snowflake } from 'discord.js'
@ -40,57 +39,18 @@ export default class DiscordAdapter {
interactionCommand.performCommand(interaction, this.registration)
})
}
public async echoes(interaction: CommandInteraction, registration: RegistrationHandler): Promise<void> {
const value = interaction.options.getString('input')
const member: GuildMember = <GuildMember>interaction.member
try {
console.log(`Member ${member.user.username} mute state: ${member.voice.mute}`)
member.voice.setMute(!member.voice.mute, "test")
} catch (error) {
console.error(error)
public async showNext(interaction: CommandInteraction): Promise<void> {
const guild = interaction.guild
if (!guild) {
console.log(`There is no guild here`)
return
}
await interaction.reply(`This should be an echo: ${value}`)
}
public async listUsers(interaction: CommandInteraction, registration: RegistrationHandler): Promise<void> {
const result = registration.listRegisteredMembers()
await interaction.reply(result)
}
public async removeUser(interaction: CommandInteraction, registration: RegistrationHandler): Promise<void> {
const discordUser: GuildMember = <GuildMember>interaction.member
registration.removeUser(discordUser)
await interaction.reply(`User has been removed`)
const output = new eventHandler().getNextEvent(guild)
await interaction.reply(output)
return
}
public async registerUser(interaction: CommandInteraction, registration: RegistrationHandler): Promise<void> {
const discordUser: GuildMember = <GuildMember>interaction.member
const steamNameToRegister = interaction.options.getString('steamname')
console.dir(discordUser)
if (!steamNameToRegister) {
await interaction.reply(`No steam name supplied, can't register`)
}
else {
registration.register(discordUser, steamNameToRegister)
await interaction.reply(`This should register user ${discordUser.user.username} with id ${discordUser.user.id} to use steamname: ${steamNameToRegister}`)
}
return
}
public async showForSteam(interaction: CommandInteraction, registration: RegistrationHandler): Promise<void> {
const steamName = interaction.options.getString('steamname')
if (!steamName) {
await interaction.reply(`No steam name supplied, can't search`)
} else {
const result = registration.getNameRegisteredForSteamUser(steamName)
await interaction.reply(JSON.stringify(result, null, 2))
}
return
}
public async showNext(interaction: CommandInteraction, registration: RegistrationHandler): Promise<void> {
const discordUser: GuildMember = <GuildMember>interaction.member
const result = registration.getNameRegisteredForDiscordUser(discordUser)
await interaction.reply(JSON.stringify(result, null, 2))
return
}
public async listEvents(interaction: CommandInteraction, registration: RegistrationHandler): Promise<void> {
public async listEvents(interaction: CommandInteraction): Promise<void> {
const guild = interaction.guild
if (!guild) {
console.log(`There is no guild here`)
@ -102,19 +62,6 @@ export default class DiscordAdapter {
}
public commandList: discordCommand[] = [
{
name: "echo",
description: "Echoes a string",
performCommand: this.echoes,
options: [
{
name: 'input',
description: 'The input that should be echoed',
required: true,
type: 3
}
]
},
{
name: "shownext",
description: "Shows next Events",

View File

@ -5,6 +5,16 @@ export default class eventHandler {
public constructor() {
console.log('constructed')
}
public getNextEvent(guild: Guild): string {
const eventManager = guild.scheduledEvents
const events = eventManager.cache
const sortedEvents = events.sort(function(a, b) { return Number(a.scheduledStartAt) - Number(b.scheduledStartAt) })
console.log(JSON.stringify(events))
console.log(JSON.stringify(sortedEvents))
return sortedEvents.first()?.toString() ?? ""
}
public listAllEvents(guild: Guild): string {
const eventManager = guild.scheduledEvents
@ -14,6 +24,7 @@ export default class eventHandler {
for (const e of entries) {
console.log(e)
output += "\n"
output += e.toString()
}
console.log(output)