diff --git a/bot-commands.js b/bot-commands.js index 70e74dc..5b5254d 100644 --- a/bot-commands.js +++ b/bot-commands.js @@ -14,6 +14,7 @@ const RoleID = require('./role-id'); const Sleep = require('./sleep'); const UserCache = require('./user-cache'); const yen = require('./yen'); +const zerg = require('./zerg'); // The given Discord message is already verified to start with the !ping prefix. // This is an example bot command that has been left in for fun. Maybe it's @@ -275,16 +276,19 @@ async function SendWipeBadgeOrders(user, discordMessage, discordMember) { await discordMessage.channel.send(`Sending orders to ${name}`); const rankNameAndInsignia = user.getRankNameAndInsignia(); let content = `${rankNameAndInsignia},\n\n`; - content += `September 2024 is shaping up to be a huge month for The Government. Lots of big groups with great leaders are committed to building nearby each other with common walls. If you miss the big old gov wipes, you need to check this out!\n\n`; + content += `Last month we did big raids almost every night. In October we will do the same and a lot of people are pumped. It is going to be a massive month.\n\n`; if (user.rank <= 21) { - content += `The build spot is P25. Use the wipe code to get into community base.\n\n`; + content += `The build spot is AA6. Run straight there and slap down your own base.\n\n`; } content += '```client.connect USLarge.Rustopia.gg```\n'; // Only one newline after triple backticks. if (user.rank <= 15) { - content += `Generals Code 3677\n`; + content += `Generals Code 0155\n`; } if (user.rank <= 19) { - content += `Wipe Code 0425\n`; + content += `Wipe Code 6463\n`; + } + if (user.rank <= 19) { + content += `All officers are invited to the opt-in zerg base. Anyone who joins the zerg base can't have any other base. You don't have to opt-in and can build your own base if you want.\n`; } console.log('Content length', content.length, 'characters.'); try { @@ -995,6 +999,7 @@ async function Dispatch(discordMessage) { '!gender': HandleGenderCommand, '!hype': HandleHypeCommand, '!impeach': HandleImpeachCommand, + '!initzerg': zerg.InitZergCommand, '!prez': HandlePrezCommand, '!veep': HandleVeepCommand, '!lottery': yen.DoLottery, diff --git a/discord-util.js b/discord-util.js index da99b96..e7470ce 100644 --- a/discord-util.js +++ b/discord-util.js @@ -21,7 +21,10 @@ const client = new Discord.Client({ ], partials: [ Discord.Partials.Channel, + Discord.Partials.GuildMember, Discord.Partials.Message, + Discord.Partials.Reaction, + Discord.Partials.User, ] }); diff --git a/server.js b/server.js index b1f4df0..164f4fa 100644 --- a/server.js +++ b/server.js @@ -20,6 +20,7 @@ const rules = require('./rules'); const TimeTogetherStream = require('./time-together-stream'); const UserCache = require('./user-cache'); const yen = require('./yen'); +const zerg = require('./zerg'); // Used for streaming time matrix data to the database. const timeTogetherStream = new TimeTogetherStream(new Clock()); @@ -398,10 +399,11 @@ async function Start() { await cu.setCitizen(true); await cu.seenNow(); await Ban.HandlePossibleReaction(messageReaction, user, true); + await zerg.HandleReactionAdd(messageReaction, user); }); discordClient.on('messageReactionRemove', async (messageReaction, user) => { - // Do nothing. + await zerg.HandleReactionRemove(messageReaction, user); }); //discordClient.on('rateLimit', (rateLimitData) => { diff --git a/zerg.js b/zerg.js new file mode 100644 index 0000000..bd1034d --- /dev/null +++ b/zerg.js @@ -0,0 +1,71 @@ +const DiscordUtil = require('./discord-util'); +const UserCache = require('./user-cache'); + +async function InitZergCommand(discordMessage) { + const cu = await UserCache.GetCachedUserByDiscordId(discordMessage.member.id); + if (!cu) { + return; + } + if (cu.commissar_id !== 7) { + return; + } + const guild = await DiscordUtil.GetMainDiscordGuild(); + const channel = await guild.channels.fetch('1291189726279241739'); + await channel.send('Signup list goes here'); +} + +async function UpdateZergList() { + console.log('Updating zerg list'); + const guild = await DiscordUtil.GetMainDiscordGuild(); + const channel = await guild.channels.fetch('1291189726279241739'); + const message = await channel.messages.fetch('1291193875033096192'); + const reaction = await message.reactions.resolve('✅'); + const fetchedReaction = await reaction.fetch(); + const users = await fetchedReaction.users.fetch(); + const names = []; + for (const [userId, user] of users) { + let member = null; + try { + member = await guild.members.fetch(userId); + } catch (error) { + member = null; + } + if (member) { + names.push(member.nickname); + } + } + let signUpList = '```Click the button to sign up.```'; + if (names.length > 0) { + names.sort(); + signUpList = '```' + names.join('\n') + '```'; + } + await message.edit(`Press the button to join the zerg base. If you join then you can't have any other base. Everyone on the list will keep 100% of their loot in the zerg base. We go straight to T3 and start raiding without wasting hours making individual bases. The plan is to snowball 24/7 in shifts.\n${signUpList}`); +} + +async function HandleReactionAdd(reaction, user) { + if (reaction.message.id !== '1291193875033096192') { + return; + } + const discordId = user.id; + const guild = await DiscordUtil.GetMainDiscordGuild(); + const member = await guild.members.fetch(discordId); + await DiscordUtil.AddRole(member, '1291210093064618025'); + await UpdateZergList(); +} + +async function HandleReactionRemove(reaction, user) { + if (reaction.message.id !== '1291193875033096192') { + return; + } + const discordId = user.id; + const guild = await DiscordUtil.GetMainDiscordGuild(); + const member = await guild.members.fetch(discordId); + await DiscordUtil.RemoveRole(member, '1291210093064618025'); + await UpdateZergList(); +} + +module.exports = { + HandleReactionAdd, + HandleReactionRemove, + InitZergCommand, +};