public async Task SetAlwaysActive(CommandContext ctx, string mention) { var user = ctx.Guild.Members.First(x => mention.Contains(x.Id.ToString())); using (var data = new SqliteDataConnector(ctx.Guild)) { if (!data.IsInDatabase(user)) { data.SetActive(user); await ctx.Message.RespondAsync(user.Mention + " added to active members"); } data.SetAlwaysActive(user, true); } }
public async Task SetActive(CommandContext ctx, string mention) { var user = ctx.Guild.Members.First(x => x.Mention.Equals(mention)); using (var data = new SqliteDataConnector(ctx.Guild)) { if (!data.IsInDatabase(user)) { data.SetActive(user); await ctx.Message.RespondAsync(user.Mention + " added to active members"); } else { await ctx.Message.RespondAsync(user.DisplayName + " is already an active member"); } } }
private static async Task MainAsync(string[] args) { discord = new DiscordClient(new DiscordConfiguration { Token = "SUPERSECRET", TokenType = TokenType.Bot }); var commandConfig = new CommandsNextConfiguration(); commandConfig.StringPrefixes = new List <string>() { "!!" }; commands = discord.UseCommandsNext(commandConfig); discord.MessageCreated += (messageCreateEventArgs) => { if (messageCreateEventArgs.Guild == null && !messageCreateEventArgs.Author.IsBot) { lock (fileLock) { using (StreamWriter sw = new StreamWriter(logFile, true)) { if (messageCreateEventArgs.Message.Content.StartsWith("!!")) { sw.WriteLine("[" + DateTime.UtcNow.ToShortTimeString() + "]" + "[CMD]" + "(" + messageCreateEventArgs.Author.Mention + " aka " + messageCreateEventArgs.Author.Username + ")" + messageCreateEventArgs.Message.Content); } else { sw.WriteLine("[" + DateTime.UtcNow.ToShortTimeString() + "]" + "[MSG]" + "(" + messageCreateEventArgs.Author.Mention + " aka " + messageCreateEventArgs.Author.Username + ")" + messageCreateEventArgs.Message.Content); } } } } return(null); }; discord.MessageCreated += (messageCreateEventArgs) => { if (messageCreateEventArgs.Message.Content.ToLower().EndsWith("stop")) { messageCreateEventArgs.Message.RespondAsync("**HAMMERTIME**"); } return(null); }; discord.MessageCreated += async(messageCreateEventArgs) => { Regex pr0grammLinkRegex = new Regex("pr0gramm\\.com\\/[newtopuser]+\\/[\\/a-zA-Z]*([0-9]+)"); var msg = messageCreateEventArgs.Message.Content; var mention = messageCreateEventArgs.Message.Author.Mention; var apiUrl = @"http://pr0gramm.com/api/items/get?id="; var apiUrlComments = @"http://pr0gramm.com/api/items/info?itemId="; var matches = pr0grammLinkRegex.Matches(msg); if (matches.Count > 0 && !msg.Contains("\n") && !messageCreateEventArgs.Author.IsBot) { var id = matches.FirstOrDefault().Groups[1].ToString(); string thumb = ""; string comment = ""; string link = ""; using (HttpClient client = new HttpClient()) using (HttpResponseMessage response = await client.GetAsync(apiUrl + id)) using (HttpContent content = response.Content) { string jsonString = await content.ReadAsStringAsync(); var json = JObject.Parse(jsonString); JToken pr0Result; json.TryGetValue("items", out pr0Result); var item = pr0Result.FirstOrDefault(); var image = item["image"].ToString(); if (image.EndsWith("jpg") || image.EndsWith("png") || image.EndsWith("gif")) { thumb = @"http://img.pr0gramm.com/" + image; } else { thumb = @"http://thumb.pr0gramm.com/" + item["thumb"]; } id = item["id"].ToString(); link = @"http://pr0gramm.com/new/" + id; } using (HttpClient client = new HttpClient()) using (HttpResponseMessage response = await client.GetAsync(apiUrlComments + id)) using (HttpContent content = response.Content) { string jsonString = await content.ReadAsStringAsync(); var json = JObject.Parse(jsonString); JToken pr0Result; json.TryGetValue("comments", out pr0Result); int upvotes = 0; foreach (var item in pr0Result) { if (int.Parse(item["up"].ToString()) > upvotes) { upvotes = int.Parse(item["up"].ToString()); comment = item["content"].ToString(); } } } await messageCreateEventArgs.Message.RespondAsync(mention); await messageCreateEventArgs.Message.RespondAsync(thumb); await messageCreateEventArgs.Message.RespondAsync(link + "\nComment: *" + comment + "*"); await messageCreateEventArgs.Message.DeleteAsync(); } }; discord.MessageCreated += async(messageCreateEventArgs) => { try { var data = new SqliteDataConnector(messageCreateEventArgs.Guild); if (data.IsInDatabase(messageCreateEventArgs.Author)) { data.UpdateActivity(messageCreateEventArgs.Author); } } catch (Exception) { } }; commands.CommandExecuted += (commandExecutionEventArgs) => { var ctx = commandExecutionEventArgs.Context; ctx.Message.DeleteAsync(); return(null); }; commands.RegisterCommands <PublicCommands>(); commands.RegisterCommands <Commands.Information>(); commands.RegisterCommands <Commands.Administration>(); commands.RegisterCommands <Commands.Pr0gramm>(); await discord.ConnectAsync(); await Task.Delay(-1); }