public async Task <Embed> StatEmbed() { EmbedBuilder e = new EmbedBuilder(); e.WithAuthor((await StaticBase.GetUserAsync(Id)).Username, (await StaticBase.GetUserAsync(Id)).GetAvatarUrl()); e.WithCurrentTimestamp().WithColor(Discord.Color.Blue); e.AddField("Level", $"{CalcCurLevel()} ({Experience}/{CalcExperience(CalcCurLevel() + 1)}xp)\n{DrawProgressBar()}", true); e.AddField("Interactions", $"**Kissed** {Kissed} times\n**Hugged** {Hugged} times\n**Punched** {Punched} times", true); e.AddField("Votepoints", Money, false); if (MessageGraph != null) { InitPlot(); if (MessageGraph.PlotDataPoints.Last().Value.Key < OxyPlot.Axes.DateTimeAxis.ToDouble(DateTime.Today)) { MessageGraph.AddValue("Value", MessageGraph.PlotDataPoints.Last().Value.Value, OxyPlot.Axes.DateTimeAxis.ToDateTime(MessageGraph.PlotDataPoints.Last().Value.Key).AddDays(1).AddMilliseconds(-1), false, false); MessageGraph.AddValue("Value", 0, OxyPlot.Axes.DateTimeAxis.ToDateTime(MessageGraph.PlotDataPoints.Last().Value.Key).AddDays(1), false, false); MessageGraph.AddValue("Value", 0, DateTime.Now, false, false); } else { MessageGraph.AddValue("Value", MessageGraph.PlotDataPoints.Last().Value.Value, DateTime.Now, false, false); } e.WithImageUrl(MessageGraph.DrawPlot()); } return(e.Build()); }
public override async Task <TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) { var command = context.Message.Content; var prefix = await StaticBase.GetGuildPrefixAsync(context.Guild.Id); if (!command.StartsWith(prefix)) { prefix = Program.Client.CurrentUser.Mention; } var module = command.Remove(0, prefix.Length).Split(" ").First(x => x.Length > 0); var worked = Enum.TryParse <TrackerType>(module, true, out TrackerType type); if (!new List <TrackerType> { TrackerType.HTML, TrackerType.JSON, TrackerType.Overwatch, TrackerType.RSS, TrackerType.Youtube, TrackerType.YoutubeLive, TrackerType.GW2 }.Any(x => x == type)) { input = input.ToLower(); } var result = StaticBase.Trackers[type].GetTracker(context.Channel.Id, input); if (result != null) { return(TypeReaderResult.FromSuccess(result)); } await MopsBot.Data.Interactive.MopsPaginator.CreatePagedMessage(context.Channel.Id, StaticBase.Trackers[type].GetTrackersEmbed(context.Channel.Id, true)); return(TypeReaderResult.FromError(CommandError.ParseFailed, $"Could not find a {module}-tracker for {input} in this channel.")); }
public async Task <Embed> GetLeaderboardAsync(Func <TwitchUser, double> stat = null, int begin = 1, int end = 10) { if (stat == null) { stat = x => x.Points; } users = users.OrderByDescending(x => stat(x)).Skip(begin - 1).Take(end - (begin - 1)).ToList(); List <KeyValuePair <string, double> > stats = new List <KeyValuePair <string, double> >(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < end - (begin - 1); i++) { if (end - begin < 10) { sb.Append($"#{begin + i}: {(await StaticBase.GetUserAsync(users[i].DiscordId))?.Mention ?? $"<@{users[i].DiscordId}>"}\n"); } stats.Add(KeyValuePair.Create("" + (begin + i), stat(users[i]))); } var embed = new EmbedBuilder(); return(embed.WithCurrentTimestamp().WithImageUrl(ColumnPlot.DrawPlotSorted(DiscordId + "Leaderboard", stats)) .WithDescription(sb.ToString()).Build()); }
private async Task <Embed> FightEmbed() { NextEnemyMove = Enemy.GetNextMove(); Log.Add($"The {Enemy.Name} is preparing to use [{NextEnemyMove.Name}]!"); EmbedBuilder e = new EmbedBuilder(); e.WithAuthor((await StaticBase.GetUserAsync(tmpUser.Id)).Username, (await StaticBase.GetUserAsync(tmpUser.Id)).GetAvatarUrl()); e.WithThumbnailUrl(Enemy.ImageUrl); e.AddField("Stats", $"HP: {Health}/{(await User.GetUserAsync(tmpUser.Id)).CalcCurLevel() + Weapon.BaseDefence + 10}\n" + $"Rage: {Rage}!!!", true); e.AddField("Enemy Stats", $"HP: {Enemy.Health}\n" + $"Rage: {Enemy.Rage}!!!", true); StringBuilder options = new StringBuilder(); int i = 0; foreach (var move in Weapon.Moveset) { options.AppendLine($"{ReactionPoll.EmojiDict[i++]}: {move.ToString(Weapon.BaseDamage, Weapon.BaseDefence, (int)(NextEnemyMove.DamageModifier * Enemy.Damage))}"); } e.AddField("Skills", options, true); e.AddField("Enemy Skills", string.Join("\n", Enemy.MoveList.Select(x => x.ToString(Enemy.Damage, Enemy.Defence, 0))), true); e.AddField("Log", $"```css\n{string.Join("\n\n", Log)}```"); return(e.Build()); }
/// <summary> ///根据查询条件判断数据是否存在 /// </summary> /// <param name="strwhere">查询条件(不需要 where 关键字)</param> /// <returns>true false</returns> public bool Exist <T>(string strwhere) { strwhere = StaticBase.SqlFilter(strwhere, 0); Type t = typeof(T); string strSql = "select count(1) from " + t.Name; if (strwhere.ToLower().Contains("where")) { strSql += strwhere; } else { strSql += " where " + strwhere; } var rv = respository.ExecuteScalar <int>(strSql); if (rv.Result == 1) { int count = rv.Info; if (count > 0) { return(true); } } return(false); }
public static async Task <Embed> GetLeaderboardAsync(ulong?guildId = null, Func <User, double> stat = null, int begin = 1, int end = 10) { var usersInGuild = guildId != null?Program.Client.GetGuild(guildId.Value).Users.Select(x => x.Id).ToHashSet() : null; var users = guildId != null?await(await StaticBase.Database.GetCollection <User>("Users").FindAsync(x => usersInGuild.Contains(x.Id))).ToListAsync() : await(await StaticBase.Database.GetCollection <User>("Users").FindAsync(x => true)).ToListAsync(); if (stat == null) { stat = x => x.CalcCurLevelDouble(); } users = users.OrderByDescending(x => stat(x)).Skip(begin - 1).Take(end - (begin - 1)).ToList(); List <KeyValuePair <string, double> > stats = new List <KeyValuePair <string, double> >(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < end - (begin - 1); i++) { if (end - begin < 10) { sb.Append($"#{begin+i}: {(await StaticBase.GetUserAsync(users[i].Id))?.Mention ?? $"<@{users[i].Id}>"}\n"); } stats.Add(KeyValuePair.Create("" + (begin + i), stat(users[i]))); } var embed = new EmbedBuilder(); return(embed.WithCurrentTimestamp().WithImageUrl(ColumnPlot.DrawPlotSorted(guildId + "Leaderboard", stats)) .WithDescription(sb.ToString()).Build()); }
/// <summary> ///执行一条sql语句 /// </summary> /// <param name="strSql">Sql语句</param> /// <param name="isone">true 一条sql语句 </param> /// <param name="type">0 查询 1 添加 2 修改 3 删除</param> /// <returns>返回受影响的行数</returns> public int Execute(string strSql, bool isone, int type) { int count = 0; strSql = StaticBase.SqlFilter(strSql, type, isone); var rv = respository.Execute <int>(strSql); if (rv.Result == 1) { count = rv.Info; } return(count); }
/// <summary> ///分页查询--数据总量查询 未开放 /// </summary> /// <param name="strwhere">查询条件(不需要 where 关键字)</param> /// <param name="pagecount">每页条数</param> private PageInfo ListCount <T>(string strwhere, int pagecount = 10) { PageInfo model = new PageInfo(); if (!string.IsNullOrEmpty(strwhere)) { strwhere = " where " + strwhere; } strwhere = StaticBase.WhereFilter(strwhere); var rv = respository.GetCountPage <T>(pagecount, strwhere, null); model.Count = rv.RecordCount; return(model); }
public override async Task <TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) { var command = context.Message.Content; var prefix = await StaticBase.GetGuildPrefixAsync(context.Guild.Id); if (!command.StartsWith(prefix)) { prefix = Program.Client.CurrentUser.Mention; } var module = command.Remove(0, prefix.Length).Split(" ").First(x => x.Length > 0); var worked = Enum.TryParse <TrackerType>(module, true, out TrackerType type); if (!CapSensitive.Any(x => x == type)) { input = input.ToLower(); } var result = StaticBase.Trackers[type].GetTracker(context.Channel.Id, input); if (result != null) { result.LastCalledChannelPerGuild[context.Guild.Id] = context.Channel.Id; return(TypeReaderResult.FromSuccess(result)); } result = StaticBase.Trackers[type].GetGuildTrackers(context.Guild.Id).FirstOrDefault(x => x.Name.Equals(input)); if (result == null) { await MopsBot.Data.Interactive.MopsPaginator.CreatePagedMessage(context.Channel.Id, StaticBase.Trackers[type].GetTrackersEmbed(context.Channel.Id, true)); return(TypeReaderResult.FromError(CommandError.ParseFailed, $"Could not find a {module}-tracker for {input}.")); } var guildChannels = (await context.Guild.GetTextChannelsAsync()).Select(x => x.Id); var channelMatches = result.ChannelConfig.Keys.Where(x => guildChannels.Any(y => y.Equals(x))); if (channelMatches.Count() == 1) { result.LastCalledChannelPerGuild[context.Guild.Id] = channelMatches.First(); return(TypeReaderResult.FromSuccess(result)); } await MopsBot.Data.Interactive.MopsPaginator.CreatePagedMessage(context.Channel.Id, StaticBase.Trackers[type].GetTrackersEmbed(context.Channel.Id, true, input)); return(TypeReaderResult.FromError(CommandError.ParseFailed, $"Multiple trackers for {input} across multiple channels.\nPlease repeat the command in the channel containing the tracker you meant.")); }
private async Task <Embed> EndEmbed() { EmbedBuilder e = new EmbedBuilder(); e.WithAuthor((await StaticBase.GetUserAsync(tmpUser.Id)).Username, (await StaticBase.GetUserAsync(tmpUser.Id)).GetAvatarUrl()); e.WithThumbnailUrl(Enemy.ImageUrl); e.AddField("Stats", $"HP: {Health}/{tmpUser.CalcCurLevel() + Weapon.BaseDefence + 10}\n" + $"Rage: {Rage}!!!", true); e.AddField("Enemy Stats", $"HP: {Enemy.Health}\n" + $"Rage: {Enemy.Rage}!!!", true); e.AddField("Log", $"```css\n{string.Join("\n\n", Log)}```"); return(e.Build()); }
/// <summary> ///分页查询--列表查询 未开放 /// </summary> /// <param name="strwhere">查询条件(不需要 where 关键字)</param> /// <param name="pageindex">第几页</param> /// <param name="pagecount">每页条数</param> /// <param name="orderby">排序</param> private PageInfo ListPage <T>(string strwhere, int pageindex = 1, int pagecount = 10, string orderby = "id") { PageInfo model = new PageInfo(); if (!string.IsNullOrEmpty(strwhere)) { if (!strwhere.ToLower().Contains("where")) { strwhere = " where " + strwhere; } } strwhere = StaticBase.WhereFilter(strwhere); var rv = respository.GetListPage <T>(pageindex, pagecount, strwhere, orderby, null); model.Count = rv.RecordCount; model.Info = rv.ContentList; return(model); }
public async Task <Embed> StatEmbed(ulong guildId) { EmbedBuilder e = new EmbedBuilder(); e.WithAuthor((await StaticBase.GetUserAsync(DiscordId)).Username, (await StaticBase.GetUserAsync(DiscordId)).GetAvatarUrl()); e.WithCurrentTimestamp().WithColor(Discord.Color.Blue); var rankRoleId = StaticBase.TwitchGuilds[guildId].RankRoles.LastOrDefault(x => x.Item1 <= Points)?.Item2 ?? 0; e.AddField("Rank", $"{(rankRoleId != 0 ? Program.Client.GetGuild(guildId).GetRole(rankRoleId).Name : "Nothing")}", false); e.AddField("Information", $"Hosted {Hosts.Count} times\nStreamed {LiveCount} times", true); e.AddField("Points", Points, true); var hosts = string.Join("\n", Hosts.TakeLast(Math.Min(Hosts.Count, 10)).Select(x => $"`{x.Item1}`: hosted [{x.Item2}](https://www.twitch.tv/{x.Item2}) for {x.Item3} viewers.")); e.AddField("Recent hosts", string.IsNullOrEmpty(hosts) ? "None" : hosts); return(e.Build()); }
/// <summary> ///返回首行列数据 /// </summary> ///<param name="strwhere">查询条件(不需要 where 关键字)</param> ///<param name="columnName">要查询的列名 默认为查询条数</param> /// <returns>返回首行首列数据</returns> public dynamic Scalar <T>(string strwhere, string columnName = " count(1) ") { strwhere = StaticBase.SqlFilter(strwhere, 0); Type t = typeof(T); string strSql = "select " + columnName + " from " + t.Name; if (strwhere.ToLower().Contains("where")) { strSql += strwhere; } else { strSql += " where " + strwhere; } var rv = respository.ExecuteScalar <int>(strSql); if (rv.Result == 1) { return(rv.Info); } return(null); }
public async Task Hosting(string hosterName, string targetName, int viewers) { await ModifyAsync(x => x.Hosts.Add(new Tuple <DateTime, string, int>(DateTime.UtcNow, targetName, viewers))); var hosterDiscordName = (await StaticBase.GetUserAsync(DiscordId)).Username; var curGuild = StaticBase.TwitchGuilds[GuildId]; curGuild.ExistsUser(targetName, out TwitchUser user); var targetDiscordId = user?.DiscordId; //ToDo: Only do once int reward = -40; if (targetDiscordId != null) { reward = 20; } await ModifyAsync(x => x.Points += reward); var embed = new EmbedBuilder().WithCurrentTimestamp().WithFooter(x => { x.IconUrl = "https://media-elerium.cursecdn.com/attachments/214/576/twitch.png"; x.Text = "Twitch Hosting"; }); embed.WithDescription($"[{hosterDiscordName}](https://www.twitch.tv/{hosterName}) is now hosting " + $"[{(targetDiscordId != null ? (await StaticBase.GetUserAsync(targetDiscordId.Value)).Username : targetName)}](https://www.twitch.tv/{targetName})"); embed.AddField("Viewers", viewers, true); embed.AddField("Points", reward, true); var builtEmbed = embed.Build(); await(Program.Client.GetChannel(curGuild.notifyChannel) as Discord.IMessageChannel).SendMessageAsync(embed: builtEmbed); }
private async Task SetRole() { var curGuild = Program.Client.GetGuild(GuildId); var rankRoleId = StaticBase.TwitchGuilds[GuildId].RankRoles.LastOrDefault(x => x.Item1 <= Points)?.Item2 ?? 0; if (rankRoleId == 0) { return; } var curRole = curGuild.GetRole(rankRoleId); if (curGuild.GetUser(DiscordId).Roles.Any(x => x.Id == curRole.Id)) { return; } var rolesToRemove = curGuild.Roles.Where(x => StaticBase.TwitchGuilds[GuildId].RankRoles.Any(y => y.Item2 == x.Id) && x.Id != rankRoleId); await curGuild.GetUser(DiscordId).AddRoleAsync(curRole); await curGuild.GetUser(DiscordId).RemoveRolesAsync(rolesToRemove); await curGuild.GetTextChannel(StaticBase.TwitchGuilds[GuildId].notifyChannel).SendMessageAsync($"{(await StaticBase.GetUserAsync(DiscordId)).Mention} is now rank {curRole.Name}"); }
public async Task help([Remainder] string helpModule = null) { try { if (helpModule != null && (!Program.Handler.commands.Modules.FirstOrDefault(x => x.Name.Equals(helpModule.Split(" ").Last(), StringComparison.InvariantCultureIgnoreCase))?.IsSubmodule ?? false)) { return; } EmbedBuilder e = new EmbedBuilder(); e.WithDescription($"For more information regarding a **specific command** or **command group***,\nplease use **?{(helpModule == null ? "" : helpModule + " ")}<command>** or " + $"**{await StaticBase.GetGuildPrefixAsync(Context.Guild.Id)}help {(helpModule == null ? "" : helpModule + " ")}<command>**") .WithColor(Discord.Color.Blue) .WithAuthor(async x => { //Don't require support server shard to be online for help. This failing actually kills Mops. x.IconUrl = "https://cdn.discordapp.com/icons/435919579005321237/3e995c6b3df5776e262d8ce4a2c514c2.jpg"; //Context.Client.GetGuild(435919579005321237).IconUrl; x.Name = "Click to join the Support Server!"; x.Url = "https://discord.gg/wZFE2Zs"; }); if (helpModule == null) { foreach (var module in Program.Handler.commands.Modules.Where(x => !x.Preconditions.OfType <HideAttribute>().Any())) { if (!module.IsSubmodule) { string moduleInformation = ""; bool isTracking = module.Name.Contains("Tracking"); moduleInformation += string.Join(", ", module.Commands.Where(x => !x.Preconditions.Any(y => y is HideAttribute)).Select(x => $"[{x.Name}]({CommandHandler.GetCommandHelpImage(x.Name)})")); moduleInformation += "\n"; moduleInformation += string.Join(", ", module.Submodules.Where(x => (!isTracking || Program.TrackerLimits[x.Name]["TrackersPerServer"] > 0) && !x.Preconditions.Any(y => y is HideAttribute)).Select(x => $"[{x.Name}\\*]({CommandHandler.GetCommandHelpImage(x.Name)})")); var modulesections = moduleInformation.Length / 1024 + 1; if (modulesections > 1) { var segments = moduleInformation.Split(", "); var submoduleInformation = ""; foreach (var segment in segments) { if (submoduleInformation.Length + segment.Length > 1000) { submoduleInformation = string.Concat(submoduleInformation.SkipLast(2)); e.AddField($"**{module.Name}**", submoduleInformation); submoduleInformation = ""; } submoduleInformation += segment + ", "; } e.AddField($"**{module.Name}**", submoduleInformation); } else { e.AddField($"**{module.Name}**", moduleInformation); } } } if (StaticBase.CustomCommands.ContainsKey(Context.Guild.Id)) { e.AddField("**Custom Commands**", string.Join(", ", StaticBase.CustomCommands.Where(x => x.Key == Context.Guild.Id).First().Value.Commands.Select(x => $"`{x.Key}`"))); } } else { // var module = Program.Handler.commands.Modules.First(x => x.Name.ToLower().Equals(helpModule.ToLower())); // string moduleInformation = ""; // moduleInformation += string.Join(", ", module.Commands.Where(x => !x.Preconditions.OfType<HideAttribute>().Any()).Select(x => $"[{x.Name}]({CommandHandler.GetCommandHelpImage($"{module.Name} {x.Name}")})")); // moduleInformation += "\n"; // moduleInformation += string.Join(", ", module.Submodules.Select(x => $"{x.Name}\\*")); // e.AddField($"**{module.Name}**", moduleInformation); var prefix = await GetGuildPrefixAsync(Context.Guild.Id); e = Program.Handler.getHelpEmbed(helpModule.ToLower(), prefix, e); } await ReplyAsync("", embed : e.Build()); } catch { throw; } }
public async Task help([Remainder] string helpModule = null) { EmbedBuilder e = new EmbedBuilder(); e.WithDescription("For more information regarding a **specific command** or **command group***,\nplease use **?<command>** or " + $"**{await StaticBase.GetGuildPrefixAsync(Context.Guild.Id)}help <command>**") .WithColor(Discord.Color.Blue) .WithAuthor(async x => { x.IconUrl = (await Context.Client.GetGuildAsync(435919579005321237)).IconUrl; x.Name = "Click to join the Support Server!"; x.Url = "https://discord.gg/wZFE2Zs"; }); if (helpModule == null) { foreach (var module in Program.Handler.commands.Modules.Where(x => !x.Preconditions.OfType <HideAttribute>().Any())) { if (!module.IsSubmodule) { string moduleInformation = ""; moduleInformation += string.Join(", ", module.Commands.Where(x => !x.Preconditions.Any(y => y is HideAttribute)).Select(x => $"[{x.Name}]({CommandHandler.GetCommandHelpImage(x.Name)})")); moduleInformation += "\n"; moduleInformation += string.Join(", ", module.Submodules.Where(x => !x.Preconditions.Any(y => y is HideAttribute)).Select(x => $"[{x.Name}\\*]({CommandHandler.GetCommandHelpImage(x.Name)})")); var modulesections = moduleInformation.Length / 1024 + 1; if (modulesections > 1) { var segments = moduleInformation.Split(", "); var submoduleInformation = ""; foreach (var segment in segments) { if (submoduleInformation.Length + segment.Length > 1000) { submoduleInformation = string.Concat(submoduleInformation.SkipLast(2)); e.AddField($"**{module.Name}**", submoduleInformation); submoduleInformation = ""; } submoduleInformation += segment + ", "; } e.AddField($"**{module.Name}**", submoduleInformation); } else { e.AddField($"**{module.Name}**", moduleInformation); } } } if (StaticBase.CustomCommands.ContainsKey(Context.Guild.Id)) { e.AddField("**Custom Commands**", string.Join(", ", StaticBase.CustomCommands.Where(x => x.Key == Context.Guild.Id).First().Value.Commands.Select(x => $"`{x.Key}`"))); } } else { // var module = Program.Handler.commands.Modules.First(x => x.Name.ToLower().Equals(helpModule.ToLower())); // string moduleInformation = ""; // moduleInformation += string.Join(", ", module.Commands.Where(x => !x.Preconditions.OfType<HideAttribute>().Any()).Select(x => $"[{x.Name}]({CommandHandler.GetCommandHelpImage($"{module.Name} {x.Name}")})")); // moduleInformation += "\n"; // moduleInformation += string.Join(", ", module.Submodules.Select(x => $"{x.Name}\\*")); // e.AddField($"**{module.Name}**", moduleInformation); var prefix = await GetGuildPrefixAsync(Context.Guild.Id); e = Program.Handler.getHelpEmbed(helpModule.ToLower(), prefix, e); } await ReplyAsync("", embed : e.Build()); }