Skip to content

Commit

Permalink
Zerg signup button.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Oct 18, 2024
1 parent 6a291e5 commit 2bcdf34
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 5 deletions.
13 changes: 9 additions & 4 deletions bot-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -995,6 +999,7 @@ async function Dispatch(discordMessage) {
'!gender': HandleGenderCommand,
'!hype': HandleHypeCommand,
'!impeach': HandleImpeachCommand,
'!initzerg': zerg.InitZergCommand,
'!prez': HandlePrezCommand,
'!veep': HandleVeepCommand,
'!lottery': yen.DoLottery,
Expand Down
3 changes: 3 additions & 0 deletions discord-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
});

Expand Down
4 changes: 3 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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) => {
Expand Down
71 changes: 71 additions & 0 deletions zerg.js
Original file line number Diff line number Diff line change
@@ -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,
};

0 comments on commit 2bcdf34

Please sign in to comment.