static async Task RegisterJoinedLeft(SocketGuildUser sgUser, UserState state) { if (state == UserState.Joined) { await roleService.RestoreTempRolesAsync(sgUser); if (sgUser.Guild.Id == Settings.App.MainGuildId) { var msg = await messageService.GetMessageAsync("welcome", null); await(await sgUser.GetOrCreateDMChannelAsync()).SendMessageAsync(embed: msg.Embed); } } if (!IonicHelper.GetTextChannel(Settings.App.MainGuildId, Settings.ChannelId.Logs, out var logsChannel)) { return; } var eb = new RiftEmbed() .WithColor(state == UserState.Joined ? new Color(46, 204, 113) : new Color(231, 76, 60)) .WithAuthor("Призыватель " + (state == UserState.Joined ? "присоединился" : "вышел"), sgUser.GetAvatarUrl()) .WithDescription($"Никнейм: {sgUser.Mention} ({sgUser.Username}#{sgUser.Discriminator})") .WithFooter($"ID: {sgUser.Id.ToString()}") .WithCurrentTimestamp(); await logsChannel.SendIonicMessageAsync(new IonicMessage(eb)); }
public async Task Emotes() { var emotes = Context.Guild.Emotes.ToList(); var re = new RiftEmbed() .WithAuthor("Server emotes") .AddField("Emote", string.Join('\n', emotes.Select(x => x.Name)), true) .AddField("ID", string.Join('\n', emotes.Select(x => x.Id)), true); await Context.Channel.SendIonicMessageAsync(new IonicMessage(re)); }
public async Task LvlHelp() { if (lvlHelpEmbed is null) { var lvlHelpEmbed = new RiftEmbed() .WithDescription($"Награды за уровни на сервере\n\n" + $"Проявляйте активность в общем чате и получайте монеты, сундуки и редкие жетоны. С поднятием уровня вам будут открываться дополнительные возможности с ботом и награды будут увеличиваться.\n\n" + $"Награды за 2 уровень:\n" + $"Все призыватели получают 100 1"); } await Context.Channel.SendIonicMessageAsync(new IonicMessage(lvlHelpEmbed)); }
public async Task <IonicMessage> GetUserActionLogsAsync(IUser user) { if (user is null) { return(MessageService.UserNotFound); } var list = await DB.ModerationLogs.GetAsync(user.Id); var toxicity = await DB.Toxicity.GetAsync(user.Id); var actions = string.Join('\n', list.Select(x => { var action = FormatAction(x.Action); if (x.Duration != TimeSpan.Zero) { action += $"({x.Duration.Humanize()})"; } return(action); })); var datetime = string.Join('\n', list.Select(x => x.CreatedAt.Humanize())); var moderator = string.Join('\n', list.Select(x => { IonicHelper.GetGuildUserById(Settings.App.MainGuildId, x.ModeratorId, out var sgUser); return(sgUser is null ? "-" : sgUser.Username); })); var embed = new RiftEmbed() .WithDescription($"Досье товарища {user.Username}\nУровень токсичности: {FormatToxicityLevel(toxicity.Level)}") .AddField("Действие", actions, true) .AddField("Дата и время", datetime, true) .AddField("Модератор", moderator, true); return(new IonicMessage(embed)); }
public async Task <IonicMessage> GetLastActionsAsync() { var list = await DB.ModerationLogs.GetLastTenAsync(); var mods = string.Join('\n', list.Select(x => { IonicHelper.GetGuildUserById(Settings.App.MainGuildId, x.ModeratorId, out var sgUser); return(sgUser is null ? "-" : sgUser.Username); })); var targets = string.Join('\n', list.Select(x => { IonicHelper.GetGuildUserById(Settings.App.MainGuildId, x.TargetId, out var sgUser); return(sgUser is null ? "-" : sgUser.Username); })); var actions = string.Join('\n', list.Select(x => { var action = FormatAction(x.Action); if (x.Duration != TimeSpan.Zero) { action += $"({x.Duration.Humanize()})"; } return(action); })); var embed = new RiftEmbed() .WithDescription("Последние действия банхаммером") .AddField("Модератор", mods, true) .AddField("Нарушитель", targets, true) .AddField("Действие", actions, true); return(new IonicMessage(embed)); }
public async Task SelfTest() { var skipChecks = false; var errors = new List <string>(); var fixedRoles = 0u; var eb = new RiftEmbed().WithTitle("Self-test"); if (!IonicHelper.GetGuild(Settings.App.MainGuildId, out var guild)) { errors.Add($"Guild is null: {nameof(Settings.App.MainGuildId)}"); skipChecks = true; } var channelNames = Settings.ChannelId.GetNames(); foreach (var field in Settings.ChannelId.GetType().GetProperties()) { if (skipChecks) { break; } if (field.GetValue(Settings.ChannelId, null) is ulong value) { if (value == 0ul) { if (channelNames.ContainsKey(field.Name)) { var channelName = channelNames[field.Name]; var guildChannel = guild.Channels.FirstOrDefault( x => x.Name.Equals(channelName, StringComparison.InvariantCultureIgnoreCase)); if (guildChannel is null) { errors.Add($"Channel ID remains undefined: {field.Name} {channelName}"); continue; } Settings.ChannelId.SetValue(field.Name, guildChannel.Id); fixedRoles++; } else { errors.Add($"Channel ID remains undefined: {field.Name}"); continue; } } else if (!IonicHelper.GetTextChannel(Settings.App.MainGuildId, value, out var textChannel) && !IonicHelper.GetVoiceChannel(Settings.App.MainGuildId, value, out var voiceChannel)) { errors.Add($"No channel on server: {field.Name}"); } } } foreach (var field in Settings.Chat.GetType().GetProperties()) { if (skipChecks) { break; } var obj = field.GetValue(Settings.Chat); if (obj is ulong ulongValue) { if (ulongValue == 0ul) { errors.Add($"Chat parameter undefined: {field.Name}"); } } else if (obj is uint uintValue) { if (uintValue == 0u) { errors.Add($"Chat parameter undefined: {field.Name}"); } } } foreach (var field in Settings.Economy.GetType().GetProperties()) { if (skipChecks) { break; } try { var obj = field.GetValue(Settings.Economy); if (obj is ulong ulongValue) { if (ulongValue == 0ul) { errors.Add($"Economy parameter undefined: {field.Name}"); } } else if (obj is uint uintValue) { if (uintValue == 0u) { errors.Add($"Economy parameter undefined: {field.Name}"); } } } catch (TargetInvocationException ex) { errors.Add($"\"{field.Name}\" invokation failed: {ex.Message}"); } catch (Exception ex) { errors.Add($"Economy object exception failed: {ex.Message}"); } } var serverRoles = Context.Guild.Roles.ToList(); var roles = await DB.Roles.GetAllAsync(); foreach (var role in serverRoles) { if (skipChecks) { break; } var matchedRole = roles.FirstOrDefault(x => x.Name.Equals(role.Name)); if (matchedRole is null) { await DB.Roles.AddAsync(role); fixedRoles++; continue; } if (matchedRole.RoleId.Equals(role.Id)) { continue; } matchedRole.RoleId = role.Id; await DB.Roles.UpdateAsync(matchedRole); fixedRoles++; } if (errors.Count == 0) { eb.WithColor(0, 255, 0); eb.WithDescription("OK 👌"); } else { eb.WithColor(255, 0, 0); var errorList = string.Join('\n', errors); if (errorList.Length >= 2048) { errorList = string.Join('\n', errors.Take(10)); eb.WithDescription($"**{errors.Count.ToString()} error(s), showing first 10**\n\n{errorList}"); } else { eb.WithDescription($"**{errors.Count.ToString()} error(s)**\n\n{errorList}"); } } await Context.Channel.SendIonicMessageAsync(new IonicMessage(eb)); if (fixedRoles > 0u) { var embedMsg = new RiftEmbed() .WithColor(255, 255, 0) .WithAuthor("Self-test") .WithDescription($"Fixed {fixedRoles.ToString()} roles."); await Context.Channel.SendIonicMessageAsync(new IonicMessage(embedMsg)); } }