internal override async Task Execute(CommandObjects CommandObject) { string[] msgs = CommandObject.CommandArgs.Remove(0); if (msgs.Length == 0) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyText); return; } if (string.IsNullOrWhiteSpace(msgs[0])) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyId); return; } if (!ulong.TryParse(msgs[0], out ulong Userid)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.IdCouldntParse); return; } try { DiscordMember FoundMember = await CommandObject.Guild.GetMemberAsync(Userid); string ResultString = string.Format(CommandObject.Language.FindResult, FoundMember.Username + "#" + FoundMember.Discriminator, FoundMember.JoinedAt, FoundMember.IsOwner ? "yes" : "no", FoundMember.AvatarUrl); await CommandObject.Channel.SendMessageAsync(ResultString); } catch (NotFoundException) { await CommandObject.Channel.SendMessageAsync(CommandObject.Language.FindNotFound); } }
internal override async Task Execute(CommandObjects CommandObject) { Database.DatabaseMethods.AllowUsersMethods.AllowUsersListFind(CommandObject.Guild.Id, out List <AllowUsers> DBAllowUsersList); List <object> DBAllowUsersObjects = new List <object> { }; foreach (AllowUsers DBAllowUser in DBAllowUsersList) { Database.DatabaseMethods.RolesMethods.RoleFind(CommandObject.Guild.Id, DBAllowUser.RoleNum, out Roles DBRole); DiscordRole GuildRole = CommandObject.Guild.GetRole(DBRole.Uuid); DBAllowUsersObjects.Add(new { RegisteredName = DBAllowUser.Name, UserID = DBAllowUser.Uuid, Role = GuildRole.Name }); } object[] DBAllowUsersArray = DBAllowUsersObjects.ToArray(); string DBAllowUsersTableText = new TableFormatter().FormatObjects(DBAllowUsersArray); await CommandObject.Message.Channel.SendMessageAsync(string.Format(CommandObject.Language.DMMention, CommandObject.Message.Author.Mention)); if (string.IsNullOrWhiteSpace(DBAllowUsersTableText)) { await CommandObject.Member.SendMessageAsync(CommandObject.Language.ListNothing); } else { await CommandObject.Member.SendMessageAsync(DBAllowUsersTableText); } }
internal override async Task Execute(CommandObjects CommandObject) { Database.DatabaseMethods.RolesMethods.RolesListFind(CommandObject.Guild.Id, out List <Roles> DBRolesList); List <object> DBRolesObjects = new List <object> { }; foreach (Roles DBRole in DBRolesList) { DBRolesObjects.Add(new { RegisteredID = DBRole.Uuid, RegisteredNumber = DBRole.RoleNum, DBRole.RoleLevel }); } object[] DBRolesArray = DBRolesObjects.ToArray(); string DBRolesTableText = new TableFormatter().FormatObjects(DBRolesArray); await CommandObject.Message.Channel.SendMessageAsync(string.Format(CommandObject.Language.DMMention, CommandObject.Message.Author.Mention)); if (string.IsNullOrWhiteSpace(DBRolesTableText)) { await CommandObject.Member.SendMessageAsync(CommandObject.Language.ListNothing); } else { await CommandObject.Member.SendMessageAsync(DBRolesTableText); } }
internal override async Task Execute(CommandObjects CommandObject) { await CommandObject.Message.RespondAsync("Logging out..."); Log.Info("Logging out..."); await ConsoleExitEvent.Main(0).ConfigureAwait(false); }
internal override async Task Execute(CommandObjects CommandObject) { await CommandObject.Message.RespondAsync("Restarting..."); Log.Info("Restarting..."); await ConsoleExitEvent.Main(-1); }
internal override async Task Execute(CommandObjects CommandObject) { try { string[] msgs = CommandObject.CommandArgs.Remove(0); if (msgs.Length == 0) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyText); return; } if (string.IsNullOrWhiteSpace(msgs[0])) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyId); return; } if (!ulong.TryParse(msgs[0], out ulong msgs_ID)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.IdCouldntParse); return; } if (Database.DatabaseMethods.AllowUsersMethods.AllowUserFind(CommandObject.Guild.Id, msgs_ID, out AllowUsers DBAllowUsersID)) { if (!await Authentication.Confirmation(CommandObject)) { await CommandObject.Channel.SendMessageAsync(CommandObject.Language.AuthFailure); return; } Database.DatabaseMethods.AllowUsersMethods.AllowUserDelete(DBAllowUsersID); try { DiscordMember DeleteGuildMember = await CommandObject.Guild.GetMemberAsync(DBAllowUsersID.Uuid); string KickReason = string.Format(CommandObject.Language.KickReason, CommandObject.Member.Username + "#" + CommandObject.Member.Discriminator); await DeleteGuildMember.RemoveAsync(KickReason); } finally { string ResultText = string.Format(CommandObject.Language.DBUserDeleteSuccess, DBAllowUsersID.Name, DBAllowUsersID.Uuid); await CommandObject.Message.Channel.SendMessageAsync(ResultText); } } else { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.IdNotRegisted); return; } } catch (IndexOutOfRangeException) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.TypingMissed); } }
internal override async Task Execute(CommandObjects CommandObject) { DiscordMessage BotResponse = await CommandObject.Channel.SendMessageAsync(CommandObject.Language.PingWait); long MessageTick = CommandObject.Message.CreationTimestamp.Ticks; long ResponseTick = BotResponse.CreationTimestamp.Ticks; long PingTick = ResponseTick - MessageTick; TimeSpan PingSpan = new TimeSpan(PingTick); double Ping = PingSpan.TotalMilliseconds; await BotResponse.ModifyAsync($"{Ping}ms"); }
internal override async Task Execute(CommandObjects CommandObject) { try { string[] msgs = CommandObject.CommandArgs.Remove(0); if (msgs.Length == 0) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyText); return; } if (string.IsNullOrWhiteSpace(msgs[0])) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyId); return; } if (!ulong.TryParse(msgs[0], out ulong msgs_ID)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.IdCouldntParse); return; } if (!Database.DatabaseMethods.RolesMethods.RoleFind(CommandObject.Guild.Id, msgs_ID, out Roles DBRolesID)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.IdNotRegisted); return; } // if DBRolesID is null, processes will not be executed from here. if (!await Authentication.Confirmation(CommandObject)) { await CommandObject.Channel.SendMessageAsync(CommandObject.Language.AuthFailure); return; } Database.DatabaseMethods.RolesMethods.RoleDelete(DBRolesID); DiscordRole GuildRole = CommandObject.Guild.GetRole(DBRolesID.Uuid); string ResultText = string.Format(CommandObject.Language.DBRoleDeleteSuccess, GuildRole.Name, DBRolesID.Uuid); await CommandObject.Message.Channel.SendMessageAsync(ResultText); } catch (IndexOutOfRangeException) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.TypingMissed); } }
public void CallCommand(string protocol, object parameter, IObjectConnection connection) { if (CommandObjects.ContainsKey(protocol)) { var commandObj = CommandObjects[protocol]; if (commandObj.CanExecute?.Invoke(connection) ?? true) { var deserializedObject = commandObj.DeserializerMethod((dynamic)parameter); if (deserializedObject != null) { commandObj.CommandMethod(connection, deserializedObject); } } } }
internal override async Task Execute(CommandObjects CommandObject) { DiscordMessage RespondMessage = await CommandObject.Message.RespondAsync("Level resetting...").ConfigureAwait(false); Log.Info("Level resetting..."); if (LiteDBClient.Database.DropCollection(typeof(UserData).Name)) { await RespondMessage.ModifyAsync("UserData removed").ConfigureAwait(false); } else { await RespondMessage.ModifyAsync("UserData couldn't removed").ConfigureAwait(false); } Log.Info("UserData Removed"); }
internal override async Task Execute(CommandObjects CommandObject) { string[] msgs = CommandObject.CommandArgs.Remove(0); if (msgs.Length == 0) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyText); return; } if (string.IsNullOrWhiteSpace(msgs[0])) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyName); return; } string EmojiName = msgs[0]; try { IEnumerator <DiscordAttachment> Attachment = CommandObject.Message.Attachments.GetEnumerator(); Uri ImageUrl; if (Attachment.MoveNext()) { ImageUrl = new Uri(Attachment.Current.Url); } else { throw new UrlNotFoundException(); } WebClient GetImage = new WebClient(); byte[] Imagebyte = await GetImage.DownloadDataTaskAsync(ImageUrl); Stream Image = new MemoryStream(Imagebyte); DiscordGuildEmoji Emoji = await CommandObject.Guild.CreateEmojiAsync(EmojiName, Image); await CommandObject.Channel.SendMessageAsync(string.Format(CommandObject.Language.EmojiSuccess, ConvertEmoji(Emoji), Emoji.Name)); } catch (UrlNotFoundException) { await CommandObject.Channel.SendMessageAsync(CommandObject.Language.ImageNotFound); } }
internal override async Task Execute(CommandObjects CommandObject) { string[] msgs = CommandObject.CommandArgs.Remove(0); if (msgs.Length == 0) { Log.Debug("Channel is null"); DiscordChannel DefaultChannel = CommandObject.Guild.GetDefaultChannel(); Console.WriteLine(DefaultChannel.Name); DiscordInvite Invite = await DefaultChannel.CreateInviteAsync(); string InviteUrl = "https://discord.gg/" + Invite.Code; string Message = string.Format(CommandObject.Language.InviteResult, InviteUrl); await CommandObject.Message.Channel.SendMessageAsync(Message); return; } string InviteText = msgs[0]; string InviteIDString = InviteText.TrimStart('<', '#').TrimEnd('>'); if (!ulong.TryParse(InviteIDString, out ulong InviteID)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.InviteChannelNotFound); return; } try { DiscordChannel GetChannel = CommandObject.Guild.GetChannel(InviteID); DiscordInvite Invite = await GetChannel.CreateInviteAsync(); string InviteUrl = "https://discord.gg/" + Invite.Code; string Message = string.Format(CommandObject.Language.InviteResult, InviteUrl); await CommandObject.Message.Channel.SendMessageAsync(Message); } catch (NullReferenceException) { Log.Warning("Channel ID is not found"); await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.InviteChannelIdNotFound); } }
internal override async Task Execute(CommandObjects CommandObject) { try { string[] msgs = CommandObject.CommandArgs.Remove(0); if (msgs.Length == 0) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyText); return; } RoleLevel intRoleLevel; if (string.IsNullOrWhiteSpace(msgs[0])) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyId); return; } if (!ulong.TryParse(msgs[0], out ulong msgs_ID)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.IdCouldntParse); return; } if (string.IsNullOrWhiteSpace(msgs[1])) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyRoleNumber); return; } if (!uint.TryParse(msgs[1], out uint msgs_RoleNum)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.RoleNumberNotNumber); return; } if (string.IsNullOrWhiteSpace(msgs[2])) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyRoleLevel); return; } // Next Update MatchCollection DenyRoleLevels = Regex.Matches(msgs[2], @"\D+"); if (DenyRoleLevels.Count != 0) { List <string> DenyStrings = new List <string>(); for (int i = 0; i < DenyRoleLevels.Count; i++) { Match DenyRoleLevel = DenyRoleLevels[i]; DenyStrings.Add(DenyRoleLevel.Value); } await CommandObject.Message.Channel.SendMessageAsync(string.Format(CommandObject.Language.RoleLevelDenyText, "`" + string.Join(@"` `", DenyStrings) + "`")); return; } if (!int.TryParse(msgs[2], out int msgs_RoleLevel)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.RoleLevelNotNumber); return; } intRoleLevel = (RoleLevel)Enum.ToObject(typeof(RoleLevel), msgs_RoleLevel); if (string.IsNullOrWhiteSpace(Enum.GetName(typeof(RoleLevel), intRoleLevel))) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.RoleLevelNotFound); return; } if (Database.DatabaseMethods.RolesMethods.RoleExist(CommandObject.Guild.Id, msgs_RoleNum)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.RoleNumberRegisted); return; } if (Database.DatabaseMethods.RolesMethods.RoleExist(CommandObject.Guild.Id, msgs_ID)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.IdRegisted); return; } if (!await Authentication.Confirmation(CommandObject)) { await CommandObject.Channel.SendMessageAsync(CommandObject.Language.AuthFailure); return; } Roles InsertRoleData = Database.DatabaseMethods.RolesMethods.RoleInsert(CommandObject.Guild.Id, msgs_ID, msgs_RoleNum, Enum.GetName(typeof(RoleLevel), intRoleLevel)); DiscordRole GuildRole = CommandObject.Guild.GetRole(InsertRoleData.Uuid); string ResultText = string.Format(CommandObject.Language.DBRoleAddSuccess, InsertRoleData.Uuid, GuildRole.Name, InsertRoleData.RoleNum, InsertRoleData.RoleLevel); await CommandObject.Message.Channel.SendMessageAsync(ResultText); } catch (IndexOutOfRangeException) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.TypingMissed); } }
internal override async Task Execute(CommandObjects CommandObject) { string[] msgs = CommandObject.CommandArgs.Remove(0); if (msgs.Length == 0) { Random random = new Random(); await CommandObject.Channel.SendMessageAsync(random.NextLong(100).ToString()).ConfigureAwait(false); } else if (msgs.Length == 1) { string Maxstring = msgs[0].Split('.')[0]; if (!long.TryParse(Maxstring, out long Maxvalue)) { await CommandObject.Channel.SendMessageAsync(CommandObject.Language.RollMaxCouldntParse).ConfigureAwait(false); } else { Random random = new Random(); try { if (Maxvalue == 0) { await CommandObject.Channel.SendMessageAsync("0").ConfigureAwait(false); } else { long Resultvalue = random.NextLong(Maxvalue); await CommandObject.Channel.SendMessageAsync(Resultvalue.ToString()).ConfigureAwait(false); } } catch (ArgumentOutOfRangeException) { await CommandObject.Channel.SendMessageAsync(CommandObject.Language.RollMaxCouldntParse).ConfigureAwait(false); } } } else if (msgs.Length == 2) { string Maxstring = msgs[0].Split('.')[0]; string Minstring = msgs[1].Split('.')[0]; if (!long.TryParse(Maxstring, out long Maxvalue)) { await CommandObject.Channel.SendMessageAsync(CommandObject.Language.RollMaxCouldntParse).ConfigureAwait(false); } else { if (!long.TryParse(Minstring, out long Minvalue)) { await CommandObject.Channel.SendMessageAsync(CommandObject.Language.RollMinCouldntParse).ConfigureAwait(false); } else { try { if (Minvalue == Maxvalue) { await CommandObject.Channel.SendMessageAsync(Maxvalue.ToString()).ConfigureAwait(false); } else { Random random = new Random(); await CommandObject.Channel.SendMessageAsync(random.NextLong(Minvalue, Maxvalue).ToString()).ConfigureAwait(false); } } catch (ArgumentOutOfRangeException) { await CommandObject.Channel.SendMessageAsync(CommandObject.Language.RollMaxMinCouldntParse).ConfigureAwait(false); } } } } }
internal override async Task Execute(CommandObjects CommandObject) { string VersionString = string.Format(CommandObject.Language.Version, Client.Bot.CurrentUser.Username, Client.Version); await CommandObject.Message.Channel.SendMessageAsync(VersionString); }
internal override async Task Execute(CommandObjects CommandObject) { Log.Debug("Start Config"); string[] msgs = CommandObject.CommandArgs.Remove(0); if (msgs.Length == 0) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyText); return; } string config_arg = msgs[0].ToLower(); switch (config_arg) { case "whitelist": bool BeforeWhitelist = Database.DatabaseMethods.GuildConfigMethods.WhitelistFind(CommandObject.Guild.Id); bool AfterWhitelist = !BeforeWhitelist; Database.DatabaseMethods.GuildConfigMethods.WhitelistUpsert(CommandObject.Guild.Id, AfterWhitelist); await CommandObject.Message.Channel.SendMessageAsync(AfterWhitelist?CommandObject.Language.ConfigWhitelistTrue : CommandObject.Language.ConfigWhitelistFalse); break; case "leaveban": bool BeforeLeaveBan = Database.DatabaseMethods.GuildConfigMethods.LeaveBanFind(CommandObject.Guild.Id); bool AfterLeaveBan = !BeforeLeaveBan; Database.DatabaseMethods.GuildConfigMethods.LeaveBanUpsert(CommandObject.Guild.Id, AfterLeaveBan); await CommandObject.Message.Channel.SendMessageAsync(AfterLeaveBan?CommandObject.Language.ConfigLeaveBanTrue : CommandObject.Language.ConfigLeaveBanFalse); break; case "prefix": if (msgs.Length < 2 || string.IsNullOrWhiteSpace(msgs[1])) { await CommandObject.Message.Channel.SendMessageAsync(string.Format(CommandObject.Language.ConfigEmptyValue, config_arg)); return; } string AfterPublicPrefix = msgs[1]; string BeforePublicPrefix = Database.DatabaseMethods.GuildConfigMethods.PublicPrefixFind(CommandObject.Guild.Id); if (BeforePublicPrefix == null) { BeforePublicPrefix = CommandConfig.Prefix; } Database.DatabaseMethods.GuildConfigMethods.PublicPrefixUpsert(CommandObject.Guild.Id, AfterPublicPrefix); await CommandObject.Message.Channel.SendMessageAsync(string.Format(CommandObject.Language.ConfigPublicPrefixChange, BeforePublicPrefix, AfterPublicPrefix)); break; case "logchannel": if (msgs.Length < 2 || string.IsNullOrWhiteSpace(msgs[1])) { await CommandObject.Message.Channel.SendMessageAsync(string.Format(CommandObject.Language.ConfigEmptyValue, config_arg)); return; } if (!ulong.TryParse(msgs[1], out ulong AfterLogChannelID)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.IdCouldntParse); return; } ulong BeforeLogChannelID = Database.DatabaseMethods.GuildConfigMethods.LogChannelFind(CommandObject.Guild.Id); Database.DatabaseMethods.GuildConfigMethods.LogChannelIdUpsert(CommandObject.Guild.Id, AfterLogChannelID); if (BeforeLogChannelID == 0) { await CommandObject.Message.Channel.SendMessageAsync(string.Format(CommandObject.Language.ConfigLogChannelIDSet, AfterLogChannelID)); } else { await CommandObject.Message.Channel.SendMessageAsync(string.Format(CommandObject.Language.ConfigLogChannelIDChange, BeforeLogChannelID, AfterLogChannelID)); } break; case "language": if (msgs.Length < 2 || string.IsNullOrWhiteSpace(msgs[1])) { await CommandObject.Message.Channel.SendMessageAsync(string.Format(CommandObject.Language.ConfigEmptyValue, config_arg)); return; } string AfterLanguageString = msgs[1].ToLower(); if (!Enum.TryParse(AfterLanguageString.Replace('-', '_'), true, out Database.Enums.Language AfterLanguage)) { await CommandObject.Message.Channel.SendMessageAsync(string.Format(CommandObject.Language.ConfigLanguageNotFound, AfterLanguageString)); return; } string BeforeLanguage = Database.DatabaseMethods.GuildConfigMethods.LanguageFind(CommandObject.Guild.Id); Database.DatabaseMethods.GuildConfigMethods.LanguageUpsert(CommandObject.Guild.Id, AfterLanguage); GetLanguage GetAfterLanguage = new GetLanguage(AfterLanguage); if (BeforeLanguage == null) { await CommandObject.Message.Channel.SendMessageAsync(string.Format(GetAfterLanguage.Language_Data.ConfigLanguageSet, Enum.GetName(typeof(Database.Enums.Language), AfterLanguage).Replace('_', '-'))); } else { await CommandObject.Message.Channel.SendMessageAsync(string.Format(GetAfterLanguage.Language_Data.ConfigLanguageChange, BeforeLanguage.Replace('_', '-'), Enum.GetName(typeof(Database.Enums.Language), AfterLanguage).Replace('_', '-'))); } break; case "level": bool BeforeLevelSwitch = Database.DatabaseMethods.GuildConfigMethods.LevelSwitchFind(CommandObject.Guild.Id); bool AfterLevelSwitch = !BeforeLevelSwitch; Database.DatabaseMethods.GuildConfigMethods.LevelSwitchUpsert(CommandObject.Guild.Id, AfterLevelSwitch); await CommandObject.Message.Channel.SendMessageAsync(AfterLevelSwitch?CommandObject.Language.ConfigLevelSwitchTrue : CommandObject.Language.ConfigLevelSwitchFalse); break; default: await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.ConfigArgsNotFound); break; } }
internal override async Task Execute(CommandObjects CommandObject) { string[] msgs = CommandObject.CommandArgs.Remove(0); if (msgs.Length == 0) { uint Level = Database.DatabaseMethods.UserDataMethods.LevelFind(CommandObject.Message.Author.Id); double Exp = Database.DatabaseMethods.UserDataMethods.ExpFind(CommandObject.Message.Author.Id); if (Exp == 0) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.StatusNotRegisted); return; } double NextLevelExp = LevelSystem.ReqNextLevelExp(Level) - Exp; DiscordMember User = await CommandObject.Guild.GetMemberAsync(CommandObject.Message.Author.Id); DiscordEmbed UserStatusEmbed = new DiscordEmbedBuilder() .WithTitle(string.Format(CommandObject.Language.StatusEmbed1, string.IsNullOrWhiteSpace(User.Nickname) ? User.Username : User.Nickname)) .WithDescription(string.Format(CommandObject.Language.StatusEmbed2, User.Username + "#" + User.Discriminator, User.Id, Exp, Level, NextLevelExp)) .WithColor(new DiscordColor(0x00B06B)) .WithTimestamp(DateTime.Now) .WithFooter(string.Format("{0} Bot", CommandObject.Client.CurrentUser.Username)); await CommandObject.Message.Channel.SendMessageAsync(UserStatusEmbed); return; } else { string UserText = msgs[0]; string UserIDString = UserText.TrimStart('<', '@', '!').TrimEnd('>'); if (!ulong.TryParse(UserIDString, out ulong UserID)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.StatusUserCouldntParse); return; } uint Level = Database.DatabaseMethods.UserDataMethods.LevelFind(UserID); double Exp = Database.DatabaseMethods.UserDataMethods.ExpFind(UserID); if (Exp == 0) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.StatusNotRegisted); return; } double NextLevelExp = LevelSystem.ReqNextLevelExp(Level) - Exp; try { DiscordMember User = await CommandObject.Guild.GetMemberAsync(UserID); DiscordEmbed UserStatusEmbed = new DiscordEmbedBuilder() .WithTitle(string.Format(CommandObject.Language.StatusEmbed1, string.IsNullOrWhiteSpace(User.Nickname) ? User.Username : User.Nickname)) .WithDescription(string.Format(CommandObject.Language.StatusEmbed2, User.Username + "#" + User.Discriminator, UserID, Exp, Level, NextLevelExp)) .WithColor(new DiscordColor(0x00B06B)) .WithTimestamp(DateTime.Now) .WithFooter(string.Format("{0} Bot", CommandObject.Client.CurrentUser.Username)); await CommandObject.Message.Channel.SendMessageAsync(UserStatusEmbed); } catch (NotFoundException) { DiscordEmbed UserStatusEmbed = new DiscordEmbedBuilder() .WithTitle(string.Format(CommandObject.Language.StatusEmbed1, UserID.ToString())) .WithDescription(string.Format(CommandObject.Language.StatusEmbed2, "Unknown", UserID, Exp, Level, NextLevelExp)) .WithColor(new DiscordColor(0x00B06B)) .WithTimestamp(DateTime.Now) .WithFooter(string.Format("{0} Bot", CommandObject.Client.CurrentUser.Username)); await CommandObject.Message.Channel.SendMessageAsync(UserStatusEmbed); } } }
internal override async Task Execute(CommandObjects CommandObject) { try { string[] msgs = CommandObject.CommandArgs.Remove(0); if (msgs.Length == 0) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyText); return; } if (string.IsNullOrWhiteSpace(msgs[0])) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyId); return; } if (!ulong.TryParse(msgs[0], out ulong msgs_ID)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.IdCouldntParse); return; } if (string.IsNullOrWhiteSpace(msgs[1])) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyRoleNumber); return; } if (!uint.TryParse(msgs[1], out uint msgs_RoleNum)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.RoleNumberNotNumber); return; } if (!Database.DatabaseMethods.AllowUsersMethods.AllowUserFind(CommandObject.Guild.Id, msgs_ID, out AllowUsers DBAllowUsersID)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.IdNotRegisted); return; } if (!Database.DatabaseMethods.RolesMethods.RoleFind(CommandObject.Guild.Id, msgs_RoleNum, out Roles DBRolesNum)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.RoleNumberNotFound); return; } if (!Database.DatabaseMethods.RolesMethods.RoleFind(CommandObject.Guild.Id, DBAllowUsersID.RoleNum, out Roles DBBeforeRolesNum)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.BeforeRoleNotFound); return; } DBAllowUsersID.RoleNum = msgs_RoleNum; Database.DatabaseMethods.AllowUsersMethods.AllowUserUpdate(DBAllowUsersID); DiscordMember GuildMember = await CommandObject.Guild.GetMemberAsync(msgs_ID); DiscordRole GuildAfterRole = CommandObject.Guild.GetRole(DBRolesNum.Uuid); await GuildMember.GrantRoleAsync(GuildAfterRole); DiscordRole GuildBeforeRole = CommandObject.Guild.GetRole(DBBeforeRolesNum.Uuid); await GuildMember.RevokeRoleAsync(GuildBeforeRole); string ResultText = string.Format(CommandObject.Language.DBUserChangeRoleSuccess, GuildMember.Username + "#" + GuildMember.Discriminator, GuildBeforeRole.Name, GuildAfterRole.Name); await CommandObject.Message.Channel.SendMessageAsync(ResultText); RoleLevel DBRoleLevel = Enum.Parse <RoleLevel>(DBRolesNum.RoleLevel); bool GuildLeaveBan = Database.DatabaseMethods.GuildConfigMethods.LeaveBanFind(CommandObject.Guild.Id); if (GuildLeaveBan) { if (DBRoleLevel == RoleLevel.Public) { DiscordEmbed WelcomeEmbed = new DiscordEmbedBuilder() .WithTitle(string.Format(CommandObject.Language.DBUserChangeRoleEmbedTitle, GuildAfterRole.Name)) .AddField( CommandObject.Language.DMEmbed_Public1, CommandObject.Language.DMEmbed_Public2 ) .AddField( CommandObject.Language.DMEmbed_Public3, CommandObject.Language.DMEmbed_Public4 ) .AddField( CommandObject.Language.DMEmbed_LeaveBan1, string.Format(CommandObject.Language.DMEmbed_LeaveBan2, GuildAfterRole.Name) ) .WithColor(new DiscordColor(0x00B06B)) .WithFooter( string.Format("{0} Bot", CommandObject.Client.CurrentUser.Username) ); await GuildMember.SendMessageAsync(WelcomeEmbed); return; } else if (DBRoleLevel == RoleLevel.Moderator) { DiscordEmbed WelcomeEmbed = new DiscordEmbedBuilder() .WithTitle(string.Format(CommandObject.Language.DBUserChangeRoleEmbedTitle, GuildAfterRole.Name)) .AddField( CommandObject.Language.DMEmbed_Moderator1, CommandObject.Language.DMEmbed_Moderator2 ) .AddField( CommandObject.Language.DMEmbed_Moderator3, string.Format(CommandObject.Language.DMEmbed_Moderator4, CommandObject.Client.CurrentUser.Username) ) .AddField( CommandObject.Language.DMEmbed_Moderator5, CommandObject.Language.DMEmbed_Moderator6 ) .AddField( CommandObject.Language.DMEmbed_LeaveBan1, string.Format(CommandObject.Language.DMEmbed_LeaveBan2, GuildAfterRole.Name) ) .WithColor(new DiscordColor(0x00B06B)) .WithFooter( string.Format("{0} Bot", CommandObject.Client.CurrentUser.Username) ); await GuildMember.SendMessageAsync(WelcomeEmbed); return; } } else { if (DBRoleLevel == RoleLevel.Public) { DiscordEmbed WelcomeEmbed = new DiscordEmbedBuilder() .WithTitle(string.Format(CommandObject.Language.DBUserChangeRoleEmbedTitle, GuildAfterRole.Name)) .AddField( CommandObject.Language.DMEmbed_Public1, CommandObject.Language.DMEmbed_Public2 ) .AddField( CommandObject.Language.DMEmbed_Public3, CommandObject.Language.DMEmbed_Public4 ) .WithColor(new DiscordColor(0x00B06B)) .WithFooter( string.Format("{0} Bot", CommandObject.Client.CurrentUser.Username) ); await GuildMember.SendMessageAsync(WelcomeEmbed); return; } else if (DBRoleLevel == RoleLevel.Moderator) { DiscordEmbed WelcomeEmbed = new DiscordEmbedBuilder() .WithTitle(string.Format(CommandObject.Language.DBUserChangeRoleEmbedTitle, GuildAfterRole.Name)) .AddField( CommandObject.Language.DMEmbed_Moderator1, CommandObject.Language.DMEmbed_Moderator2 ) .AddField( CommandObject.Language.DMEmbed_Moderator3, string.Format(CommandObject.Language.DMEmbed_Moderator4, CommandObject.Client.CurrentUser.Username) ) .AddField( CommandObject.Language.DMEmbed_Moderator5, CommandObject.Language.DMEmbed_Moderator6 ) .WithColor(new DiscordColor(0x00B06B)) .WithFooter( string.Format("{0} Bot", CommandObject.Client.CurrentUser.Username) ); await GuildMember.SendMessageAsync(WelcomeEmbed); return; } } } catch (IndexOutOfRangeException) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.TypingMissed); return; } }
internal override async Task Execute(CommandObjects CommandObject) { await CommandObject.Channel.SendMessageAsync(string.Format(CommandObject.Language.DMMention, CommandObject.Member.Mention)); string GuildPrefix = Database.DatabaseMethods.GuildConfigMethods.PrefixFind(CommandObject.Guild.Id); if (GuildPrefix == null) { GuildPrefix = CommandConfig.Prefix; } DiscordEmbedBuilder PublicEmbed = new DiscordEmbedBuilder(); DiscordEmbedBuilder ModeratorEmbed = new DiscordEmbedBuilder(); DiscordEmbedBuilder BotownerEmbed = new DiscordEmbedBuilder(); foreach (CommandInfo Command_Info in CommandInfo.GetCommandInfo()) { if (Command_Info.Command_Attribute.CommandName == null) { continue; } switch (Command_Info.Command_Attribute.CommandRoleLevel) { case RoleLevel.Public: PublicEmbed.AddField( Command_Info.Command.Description[CommandObject.LanguageType], string.Format($"`{Command_Info.Command.Usage[CommandObject.LanguageType]}`", GuildPrefix) ); break; case RoleLevel.Moderator: ModeratorEmbed.AddField( Command_Info.Command.Description[CommandObject.LanguageType], string.Format($"`{Command_Info.Command.Usage[CommandObject.LanguageType]}`", GuildPrefix) ); break; case RoleLevel.Owner: BotownerEmbed.AddField( Command_Info.Command.Description[CommandObject.LanguageType], string.Format($"`{Command_Info.Command.Usage[CommandObject.LanguageType]}`", CommandConfig.Prefix) ); break; default: break; } } PublicEmbed .WithTitle(CommandObject.Language.HelpPublicCommand) .WithDescription(string.Format(CommandObject.Language.HelpCommandPrefix, GuildPrefix)) .WithColor(new DiscordColor(0x00B06B)) .WithTimestamp(DateTime.Now) .WithFooter(string.Format("{0} Bot", CommandObject.Client.CurrentUser.Username)); await CommandObject.Member.SendMessageAsync(PublicEmbed); RoleLevel DBRoleLevel = CommandObject.Message.Author.Id == CommandObject.Guild.Owner.Id || CommandObject.Message.Author.Id == ClientConfig.BotownerId ? RoleLevel.Moderator : Database.DatabaseMethods.AllowUsersMethods.AllowUserFind(CommandObject.Guild.Id, CommandObject.Message.Author.Id, out AllowUsers DBAllowUsersID) && Database.DatabaseMethods.RolesMethods.RoleFind(CommandObject.Guild.Id, DBAllowUsersID.RoleNum, out Roles DBRolesNum) ? (RoleLevel)Enum.Parse(typeof(RoleLevel), DBRolesNum.RoleLevel) : RoleLevel.Public; if (DBRoleLevel == RoleLevel.Moderator) // CommandObject.Message.Author.Id == CommandObject.Guild.Owner.Id { ModeratorEmbed .WithTitle(CommandObject.Language.HelpModeratorCommand) .WithDescription(string.Format(CommandObject.Language.HelpCommandPrefix, GuildPrefix)) .AddField( CommandObject.Language.HelpConfigArgs, "`" + "whitelist" + " | " + "leaveban" + " | " + "publicprefix" + " | " + "moderatorprefix" + " | " + "logchannel" + " | " + "language" + " | " + "level" + "`" ) .WithColor(new DiscordColor(0xF6AA00)) .WithTimestamp(DateTime.Now) .WithFooter(string.Format("{0} Bot", CommandObject.Client.CurrentUser.Username)); await CommandObject.Member.SendMessageAsync(ModeratorEmbed); } if (CommandObject.Message.Author.Id == ClientConfig.BotownerId) { BotownerEmbed .WithTitle("Botowner Commands") .WithDescription(string.Format("Prefix is {0}", CommandConfig.Prefix)) .WithColor(new DiscordColor(0x1971FF)) .WithTimestamp(DateTime.Now) .WithFooter(string.Format("{0} Bot", CommandObject.Client.CurrentUser.Username)); await CommandObject.Member.SendMessageAsync(BotownerEmbed); } }
internal override async Task Execute(CommandObjects CommandObject) { try { string[] msgs = CommandObject.CommandArgs.Remove(0); if (msgs.Length == 0) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyText); return; } string msgs_Name; if (string.IsNullOrWhiteSpace(msgs[0])) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyName); return; } msgs_Name = msgs[0]; if (string.IsNullOrWhiteSpace(msgs[1])) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyId); return; } if (!ulong.TryParse(msgs[1], out ulong msgs_ID)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.IdCouldntParse); return; } if (string.IsNullOrWhiteSpace(msgs[2])) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyRoleNumber); return; } if (!uint.TryParse(msgs[2], out uint msgs_RoleNum)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.RoleNumberNotNumber); return; } if (Database.DatabaseMethods.AllowUsersMethods.AllowUserExist(CommandObject.Guild.Id, msgs_Name)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.NameRegisted); return; } if (Database.DatabaseMethods.AllowUsersMethods.AllowUserExist(CommandObject.Guild.Id, msgs_ID)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.IdRegisted); return; } if (!Database.DatabaseMethods.RolesMethods.RoleFind(CommandObject.Guild.Id, msgs_RoleNum, out Roles DBRolesNum)) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.RoleNumberNotFound); return; } if (!await Authentication.Confirmation(CommandObject)) { await CommandObject.Channel.SendMessageAsync(CommandObject.Language.AuthFailure); return; } AllowUsers InsertAllowUserData = Database.DatabaseMethods.AllowUsersMethods.AllowUserInsert(CommandObject.Guild.Id, msgs_ID, msgs_Name, msgs_RoleNum); DiscordRole GuildRole = CommandObject.Guild.GetRole(DBRolesNum.Uuid); string ResultText = string.Format(CommandObject.Language.DBUserAddSuccess, InsertAllowUserData.Name, InsertAllowUserData.Uuid, InsertAllowUserData.RoleNum, GuildRole.Name); await CommandObject.Message.Channel.SendMessageAsync(ResultText); } catch (IndexOutOfRangeException) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.TypingMissed); } }
/// <summary> /// Process executed by <see cref="CommandRegister"/> /// </summary> internal virtual async Task Execute(CommandObjects CommandObject) { await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.CommandNotImpl).ConfigureAwait(false); }