private async Task ReactionAdded(Cacheable <IUserMessage, ulong> cach, ISocketMessageChannel chan, SocketReaction react) { if (react.UserId == Sentences.myId) { return; } if (await db.GetCloseMessageId(react.UserId, chan) == react.MessageId.ToString()) { if (react.Emote.Name == "✅") { await db.DeleteTicket(react.Channel.Id, ((ITextChannel)chan).Guild); } else if (react.Emote.Name == "❌") { await react.Message.Value.DeleteAsync(); } } else if (await db.GetMenuMessageId(react.UserId, chan) == react.MessageId.ToString()) { ITextChannel textChan = (ITextChannel)chan; if (react.Emote.Name == "1⃣") { await chan.SendMessageAsync(Sentences.category1); await textChan.ModifyAsync(x => x.CategoryId = 585809200282861581); await textChan.AddPermissionOverwriteAsync(textChan.Guild.GetRole(455505689612255243), new OverwritePermissions(viewChannel : PermValue.Allow, sendMessages : PermValue.Allow)); } else if (react.Emote.Name == "2⃣") { await chan.SendMessageAsync(Sentences.category2); await textChan.ModifyAsync(x => x.CategoryId = 484466560204013577); await textChan.AddPermissionOverwriteAsync(textChan.Guild.GetRole(455505689612255243), new OverwritePermissions(viewChannel : PermValue.Allow, sendMessages : PermValue.Allow)); } else if (react.Emote.Name == "3⃣") { await chan.SendMessageAsync(Sentences.category3); await textChan.ModifyAsync(x => x.CategoryId = 585809388221104148); } else if (react.Emote.Name == "4⃣") { await chan.SendMessageAsync(Sentences.category4); await textChan.ModifyAsync(x => x.CategoryId = 585809491493257247); await textChan.AddPermissionOverwriteAsync(textChan.Guild.GetRole(455505689612255243), new OverwritePermissions(viewChannel : PermValue.Allow, sendMessages : PermValue.Allow)); } else { return; } await(await cach.GetOrDownloadAsync()).DeleteAsync(); await textChan.AddPermissionOverwriteAsync(await textChan.Guild.GetUserAsync(react.UserId), new OverwritePermissions(viewChannel : PermValue.Allow, sendMessages : PermValue.Allow)); } }
//creates a new channel and inserts the values into a NOSQL database private async Task InsertChannel(SocketVoiceChannel voiceChannel) { ITextChannel textChannel = await voiceChannel.Guild.CreateTextChannelAsync($"{voiceChannel.Name} - Voice"); await textChannel.ModifyAsync(channel => channel.Topic = $" {voiceChannel.Name} -> {textChannel.Name}"); Log($"Created new Text Channel in {textChannel.GuildId}: {voiceChannel.Id} -> {textChannel.Id}"); string insert = @"INSERT INTO Mappings (VoiceID, TextID, Guild) VALUES ($VoiceID, $TextID, $Guild);"; SQLiteCommand command = new SQLiteCommand(insert, dbConnection); command.Parameters.Add(new SQLiteParameter("$VoiceID")); command.Parameters.Add(new SQLiteParameter("$TextID")); command.Parameters.Add(new SQLiteParameter("$Guild")); command.Parameters["$VoiceID"].Value = voiceChannel.Id; command.Parameters["$TextID"].Value = textChannel.Id; command.Parameters["$Guild"].Value = voiceChannel.Guild.Id; dbConnection.Open(); command.ExecuteScalar(); dbConnection.Close(); OverwritePermissions overwrite = new OverwritePermissions(readMessages: PermValue.Deny); await textChannel.AddPermissionOverwriteAsync(voiceChannel.Guild.EveryoneRole, overwrite); }
private static async Task MoveChannel(ITextChannel raiderChannel, ulong categoryId) { await raiderChannel.ModifyAsync(props => { props.CategoryId = new Optional <ulong?>(categoryId); }); }
/// <summary> /// Sets the Discord text channel topic /// </summary> /// <param name="topic">new channel topic</param> /// <returns>void</returns> public async Task SetTopic(string topic) { ITextChannel topicChannel = Client.GetChannel(Config.ChannelId) as ITextChannel; await topicChannel.ModifyAsync(chan => { chan.Topic = topic; }).ConfigureAwait(true); }
async Task <ITextChannel> CreateChannelAsync(ITextChannel channel, string name, string topic) { if (channel == null) { channel = await _guild.CreateTextChannelAsync(name); Log.Debug($"Channel created: '#{channel}' - '{topic ?? "<null>"}'"); } if (channel.Topic != topic) { await channel.ModifyAsync(c => c.Topic = topic); } return(channel); }
public async Task ChannelUpdateForText(SocketChannel channel1, SocketChannel channel2) { IVoiceChannel vc1 = channel1 as IVoiceChannel; IVoiceChannel vc2 = channel2 as IVoiceChannel; if (vc1 != null && vc2 != null && vc1.Name != vc2.Name) { ITextChannel assoc = await GetAssocChannel(vc1); if (assoc != null) { await assoc.ModifyAsync((TextChannelProperties tcp) => { tcp.Name = vc2.Name; }, channelAssoc); } } }
public async Task AddProject([Remainder] string projectName) { ICategoryChannel ProjectsCategory = CommandHelper.FindCategory(Context.Guild.CategoryChannels, Strings.ProjectCategoryName); string TrueName = projectName.Replace(' ', '-'); if (ProjectsCategory is null) { //Create the category ProjectsCategory = await Context.Guild.CreateCategoryChannelAsync(Strings.ProjectCategoryName); } ITextChannel ProjectChannel = await Context.Guild.CreateTextChannelAsync(TrueName); await ProjectChannel.ModifyAsync(delegate(TextChannelProperties ac) { ac.CategoryId = ProjectsCategory.Id; }); //fully order channels in category List <ITextChannel> channels = new List <ITextChannel>(Context.Guild.TextChannels); channels.RemoveAll(x => x.CategoryId != ProjectsCategory.Id); channels.Add(ProjectChannel); await CommandHelper.OrderChannels(channels, ProjectsCategory.Id); //create a role IRole ProjectManagerRole = await Context.Guild.CreateRoleAsync($"{TrueName}-Manager"); await ProjectManagerRole.ModifyAsync(delegate(RoleProperties rp) { rp.Mentionable = true; }); IRole ProjectRole = await Context.Guild.CreateRoleAsync(TrueName); await ProjectRole.ModifyAsync(delegate(RoleProperties rp) { rp.Mentionable = true; }); await((IGuildUser)Context.User).AddRolesAsync(new List <IRole> { ProjectManagerRole, ProjectRole }); await ProjectChannel.AddPermissionOverwriteAsync(ProjectManagerRole, new OverwritePermissions(manageMessages : PermValue.Allow)); await ReplyAsync($"Created {ProjectChannel.Mention} with role {ProjectRole.Mention}!"); }
public async Task SlowModeAsync( [Summary("The duration of slowmode"), OverrideTypeReader(typeof(AbbreviatedTimeSpanTypeReader))] TimeSpan duration) { EmbedBuilder builder = new EmbedBuilder(); int slowmodeDuration = (int)duration.TotalSeconds; if (slowmodeDuration > _maxSlowMode || slowmodeDuration < 0) { builder.WithColor(Color.Red) .WithDescription($"Duration ({duration.Humanize(3)}) out of bounds (0 - {_maxSlowMode / 3600} hours)!"); } else { builder.WithColor(Color.Green); if (slowmodeDuration == 0) { builder.WithDescription($"Slowmode is turned off!"); } else { builder.WithDescription($"Slowmode is set to {duration.Humanize(3)}!"); } ITextChannel channel = await Context.Guild.GetTextChannelAsync(Context.Channel.Id); await channel.ModifyAsync(x => x.SlowModeInterval = slowmodeDuration); await ModerationLog.CreateEntry(ModerationLogEntry.New .WithDefaultsFromContext(Context) .WithActionType(ModerationActionType.SlowMode) .WithDuration(duration)); } await builder.Build().SendToChannel(Context.Channel); }
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`."); }
public async Task Challenge(SocketGuildUser user = null) { // Create SocketGuildUser objects SocketGuildUser author = (Context.Message.Author as SocketGuildUser); // Creating objects string type1, type2; type1 = Convert.ToString(provider.GetFieldAwonaByID("type", Convert.ToString(author.Id), "discord_id", "users")); type2 = Convert.ToString(provider.GetFieldAwonaByID("type", Convert.ToString(user.Id), "discord_id", "users")); Archetype player1 = subcommand.CreateClass(type1, author); Archetype player2 = subcommand.CreateClass(type2, user); // If created successfully if (player1 == null) { await ReplyAsync("Ошибка при создании первого игрока"); return; } else if (player2 == null) { await ReplyAsync("Ошибка при создании второго игрока"); return; } await ReplyAsync(":white_check_mark: Создаю каналы..."); ulong context_id = Context.Channel.Id; ulong channel_id = 823844887787077682; string answer = ""; if (!subcommand.ValidChecker(user, author, ref answer, channel_id, context_id)) { await ReplyAsync(answer); return; } // // Get everyone role, create new role, create permissions, set roles // // Create user name and author name string authorname, username; authorname = Context.Message.Author.Username; username = user.Username; // Create Roles IRole everyone = Context.Guild.EveryoneRole; IRole publicrole = await Context.Guild.CreateRoleAsync($"{authorname}-vs-{username}", null, new Color(0xf5fffa), false, null); IRole firstplayer = await Context.Guild.CreateRoleAsync($"{authorname}#{authorname.Length}", null, new Color(0xf5fffa), false, null); IRole secondplayer = await Context.Guild.CreateRoleAsync($"{username}#{username.Length}", null, new Color(0xf5fffa), false, null); // Create Permissions OverwritePermissions noView = new OverwritePermissions(viewChannel: PermValue.Deny); OverwritePermissions yesView = new OverwritePermissions(viewChannel: PermValue.Allow); // Add roles to first and second player await(Context.User as IGuildUser).AddRoleAsync(publicrole); await(Context.User as IGuildUser).AddRoleAsync(firstplayer); await(user as IGuildUser).AddRoleAsync(publicrole); await(user as IGuildUser).AddRoleAsync(secondplayer); // // Create category, set permissions, create two channels // // Create category and set permissions ICategoryChannel category = await Context.Guild.CreateCategoryChannelAsync($"{authorname}-vs-{username}"); await category.AddPermissionOverwriteAsync(everyone, noView); await category.AddPermissionOverwriteAsync(firstplayer, yesView); await category.AddPermissionOverwriteAsync(secondplayer, yesView); // Create channel 1 ITextChannel authorchannel = await Context.Guild.CreateTextChannelAsync($"{authorname}-challenge"); await authorchannel.AddPermissionOverwriteAsync(everyone, noView); await authorchannel.AddPermissionOverwriteAsync(firstplayer, yesView); await authorchannel.ModifyAsync(x => x.CategoryId = category.Id); // Create channel 2 ITextChannel userchannel = await Context.Guild.CreateTextChannelAsync($"{username}-challenge"); await userchannel.AddPermissionOverwriteAsync(everyone, noView); await userchannel.AddPermissionOverwriteAsync(secondplayer, yesView); await userchannel.ModifyAsync(x => x.CategoryId = category.Id); // // Fight category // // Start message provider.ExecuteSQL($"INSERT INTO duel VALUES (\"{authorname}-vs-{username}\", \"{authorname}\", \"{username}\", {author.Id}, {user.Id}, {authorchannel.Id}, {userchannel.Id}, \"Sleep\", \"Sleep\", {player1.Health}, {player2.Health}, false, false)"); FightHandler fightHandler = new FightHandler(); await fightHandler.StartMessage(author, user, userchannel, authorchannel); await ReplyAsync(":white_check_mark: Бой начат, каналы созданы"); fightHandler.FightLoop(author, user, player1, player2, category, authorchannel, userchannel, publicrole, firstplayer, secondplayer); }
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 topic(ITextChannel channel, string s) { await channel.ModifyAsync(c => c.Topic = s); await ReplyAsync($"Channel {channel} has its topic changed"); }