diff --git a/locale/de-DE.commands.json b/locale/de-DE.commands.json index b258925bf6033d9a1ae00e2c53b302bc7e593749..796b2cfe60f9c257102e2f4566a69a31e690a5a8 100644 --- a/locale/de-DE.commands.json +++ b/locale/de-DE.commands.json @@ -92,6 +92,16 @@ "maybe": { "commands": ["vielleicht", "vllt", "eventuell", "evtl"] }, + "moddingEndRegistration": + { + "commands": [ + "RegistrierungsphaseBeenden", + "RegistrierungBeenden", + "AnmeldephaseBeenden", + "AnmeldungBeenden" + ], + "info": "Beendet die Registrierungsphase und versetzt alle vollständig registrierten Teilnehmer in den Wartezustand." + }, "moddingRunAssignment": { "commands": [ diff --git a/locale/de-DE.texts.json b/locale/de-DE.texts.json index b654f9c2061e3a42875d2dce30a05df4e67a6444..396088e5a15661a55fa022aad6707947e4237eef 100644 --- a/locale/de-DE.texts.json +++ b/locale/de-DE.texts.json @@ -38,6 +38,7 @@ "notUnderstood": "Häää? Probiers nochmal.", "oldInformation": "Dies findet sich aktuell dazu in meiner Datenbank:\n>>> {var.informationValue}", "moderationNeedHelp": "<@&{var.moderationRoleId}> Der Wichtel {contact.nickname} ({contact.tag}) bittet um Hilfe.", + "moderationRegistrationEnded": "Registrierungsphase beendet. \nAnzahl Wartender: {var.waitingMemberCount}", "moderationStatus": "**Status des Wichtelns {var.currentEventName}**\nAktuelle Phase: {var.eventPhaseString}\n\nAnzahl Teilnehmer: {var.contactCount}\nDavon vollständig registriert: {var.waitingMemberCount}\n\nBewichtelungsarten:\nAls Wichtelpate: {var.analogueGiverCount} mal analog, {var.digitalGiverCount} mal digital, {var.allGiverCount} mal beides\nAls Wichtelkind: {var.analogueTakerCount} mal analog, {var.digitalTakerCount} mal digital, {var.allTakerCount} mal beides\n\nPakete: {var.parcelSentCount} versendet, {var.parcelReceivedCount} erhalten", "moderationStatusEventPhase": "{var.currentEventPhase}", "moderationStatusEventPhaseWithNextPhase": "{var.currentEventPhase} ({var.nextEventPhase} startet am {date.day}.{date.month}.{date.year} um {date.hour}:{date.minute} Uhr)", diff --git a/scripts/utility/localisation.ts b/scripts/utility/localisation.ts index 01da981e9e0c3fff4901e9653e7a27aca9d95db9..f72d17661e92ba7f1aed6b70131c2eae4062ea10 100644 --- a/scripts/utility/localisation.ts +++ b/scripts/utility/localisation.ts @@ -27,6 +27,7 @@ interface Commands informationBothAnalogueAndDigital: CommandInfo; informationDigital: CommandInfo; maybe: CommandInfo; + moddingEndRegistration: CommandInfo; moddingRunAssignment: CommandInfo; // TODO: Rename "modding" commands to "moderation". moddingStatus: CommandInfo; no: CommandInfo; @@ -79,6 +80,7 @@ interface Texts notUnderstood: TokenString; oldInformation: TokenString; moderationNeedHelp: TokenString; // TODO: This includes a Discord specific mention which is not portable to other implementations. + moderationRegistrationEnded: TokenString; moderationStatus: TokenString; moderationStatusEventPhase: TokenString; moderationStatusEventPhaseWithNextPhase: TokenString; diff --git a/scripts/wichtelbot/database/database.ts b/scripts/wichtelbot/database/database.ts index 761644700742a729c9a59f51f6272f2f859e78e0..9b6ce448dc211273812e600530511c20e122129e 100644 --- a/scripts/wichtelbot/database/database.ts +++ b/scripts/wichtelbot/database/database.ts @@ -248,21 +248,32 @@ export default class Database */ public updateContact (contact: Contact): void { - contact.lastUpdateTime = Utils.getCurrentUnixTime(); + this.updateContacts([contact]); + } + /** + * NOTE: The contact objects's lastUpdateTime will be updated. + */ + public updateContacts (contacts: Contact[]): void + { const statement = this.mainDatabase.prepare( `UPDATE - contact - SET - tag = :tag, name = :name, nickname = :nickname, - lastUpdateTime = :lastUpdateTime, type = :type, state = :state - WHERE - id = :id` + contact + SET + tag = :tag, name = :name, nickname = :nickname, + lastUpdateTime = :lastUpdateTime, type = :type, state = :state + WHERE + id = :id` ); - statement.run( - this.getBindablesFromObject(contact) - ); + for (const contact of contacts) + { + contact.lastUpdateTime = Utils.getCurrentUnixTime(); + + statement.run( + this.getBindablesFromObject(contact) + ); + } } public getContactCount (): number diff --git a/scripts/wichtelbot/endpoint/definitions/state.ts b/scripts/wichtelbot/endpoint/definitions/state.ts index 5ab407adcaeb02d17688e416b783d4addd807b06..7f327b725314d4ab435f594a90b1b451868787f4 100644 --- a/scripts/wichtelbot/endpoint/definitions/state.ts +++ b/scripts/wichtelbot/endpoint/definitions/state.ts @@ -20,6 +20,8 @@ enum State /** Waiting for becoming a Wichtel. */ Waiting = 'waiting', // TODO: Rename to "registered". ConfirmDeregistration = 'confirmDeregistration', + /** While assignment is running; cannot change information. */ + Assignment = 'assignment', // TODO: Rename to "waiting" after "waiting" has been renamed to "registered". // As wichtel: MessageToGiftGiver = 'messageToGiftGiver', MessageToGiftTaker = 'messageToGiftTaker', diff --git a/scripts/wichtelbot/message/handlingDefinition.ts b/scripts/wichtelbot/message/handlingDefinition.ts index 401bd82a2277c417cac5b8479bb9c40781bee509..5fd8953a9b424f70feb7f0a403a1c12cc233ce98 100644 --- a/scripts/wichtelbot/message/handlingDefinition.ts +++ b/scripts/wichtelbot/message/handlingDefinition.ts @@ -497,6 +497,10 @@ export default class HandlingDefinition ]; public moderatorCommands: CommandDefinition[] = [ + { + commandInfo: Localisation.commands.moddingEndRegistration, // TODO: Remove with cron feature that does this automatically. + handlerFunction: async (message: Message): Promise<void> => this.moderationModule.endRegistration(message) + }, { commandInfo: Localisation.commands.moddingRunAssignment, handlerFunction: async (message: Message): Promise<void> => diff --git a/scripts/wichtelbot/message/modules/moderationModule.ts b/scripts/wichtelbot/message/modules/moderationModule.ts index bd0367f1a19c9a898dfc0b556f11e2ecd0612dc1..63012c1577f14b7f291bf8653eeced352957e8c9 100644 --- a/scripts/wichtelbot/message/modules/moderationModule.ts +++ b/scripts/wichtelbot/message/modules/moderationModule.ts @@ -2,7 +2,7 @@ import Config from "../../../utility/config"; import Database from "../../database/database"; import { KeyValuePairList } from "../../../utility/keyValuePair"; import Localisation from "../../../utility/localisation"; -import { Message } from "../../endpoint/definitions"; +import { Message, State } from "../../endpoint/definitions"; import Utils from "../../../utility/utils"; import WichtelEventPhase from "../../../utility/wichtelEvent"; @@ -90,4 +90,25 @@ export class ModerationModule await message.reply(answer); } + + /** + * End the registration phase and give all members that have completed the registration the "assignment" status. + */ + public async endRegistration (message: Message): Promise<void> + { + const members = this.database.getWaitingMembers(); + + for (const member of members) + { + member.state = State.Assignment; + } + + // NOTE: We can use "updateContacts" instead of "updateMembers" because we changed the state, which is only part of the contact: + this.database.updateContacts(members); + + const parameters = new KeyValuePairList('waitingMemberCount', `${members.length}`); + const answer = Localisation.texts.moderationRegistrationEnded.process(message.author, parameters); + + await message.reply(answer); + } }