public async Task GetConfirmation() { string replyMessage = "test"; int next = 0; while (next < 5) { await ReplyAsync(replyMessage); //var response = await NextMessageAsync(); var response = "n"; log.Info(response.ToString()); if (response != null || response.ToString() != "") { if (response.ToString().ToLower() == "yes" || response.ToString().ToLower() == "ye" || response.ToString().ToLower() == "y") { _ = new AdminCommands { ReplyStatus = true }; next = 10; } else if (response.ToString().ToLower() == "nah" || response.ToString().ToLower() == "no" || response.ToString().ToLower() == "n") { _ = new AdminCommands { ReplyStatus = false }; next = 10; } else { await ReplyAsync("Invalid input. Input one more time."); next++; } } } if (next < 10) { await ReplyAsync("Invalid inputs. Will close the function."); _ = new AdminCommands { ReplyStatus = false }; } }
public async Task GetInput() { TimeSpan delay = TimeSpan.FromSeconds(5); //var response = await NextMessageAsync(); var response = "no"; log.Info(response.ToString()); if (response != null || response.ToString() != "") { AdminCommands ad = new AdminCommands { Prf = response.ToString(), ReplyStatus = true }; } else { _ = new AdminCommands { ReplyStatus = false }; } }
public async Task Prefix() { log.Info("Prefix function booted up."); ObtainDatabaseInfo(); string connectionString; connectionString = @"Data Source=" + datasource + ";Initial Catalog=" + dbname + ";User ID=" + user + ";Password="******";"; log.Debug(connectionString); // Access the database using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); log.Info("Database connection established."); var guild = Context.Guild.Id; var selectQuery = "SELECT prefix FROM prefixes WHERE guildid = @Guild;"; using (SqlCommand command = new SqlCommand(selectQuery)) { command.Parameters.AddWithValue("@Guild", guild); command.Prepare(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Prf = reader.GetString(0); log.Debug("Guild ID: " + guild + " / Prefix: " + Prf); } }; }; }; await ReplyAsync("The current prefix for the bot is: ``" + Prf + "``. Enter a new prefix, otherwise leave blank to leave as is."); // Get the input of the user var response = await NextMessageAsync(); AdminCommands ac = new AdminCommands(); ac.GetInput(response.ToString()); if (ReplyStatus == false) { await ReplyAsync("No input received, the prefix will stay as ``" + Prf + "``"); } else if (ReplyStatus == true) { // Update database using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); var guild = Context.Guild.Id; var updateQuery = "INSERT INTO prefixes VALUES(@Guild,@Prefix) ON DUPLICATE KEY UPDATE prefix = @Prefix"; using (SqlCommand command = new SqlCommand(updateQuery)) { // Two different ways to add // command.Parameters.Add("@Prefix", SqlDbType.VarChar).Value = Prf; command.Parameters.AddWithValue("@Prefix", Prf); command.Parameters.AddWithValue("Guild", guild); command.Prepare(); command.ExecuteNonQuery(); }; }; } }
public async Task DeleteAndLog(params string[] args) { IEnumerable <IMessage> message = await Context.Channel.GetMessagesAsync().FlattenAsync();; int result; bool validReturn; bool withName = false; string replyMessage = ""; string[] parameters = args; string filename = ""; log.Info("Starting up the Delete and Log function."); if (parameters.Length == 0) { parameters = new string[] { "100" }; var input = parameters[0]; message = await Context.Channel.GetMessagesAsync(Convert.ToInt32(input)).FlattenAsync(); replyMessage = "Are you sure you want to delete " + input + " lines? [Y/N]"; validReturn = true; } else if (parameters.Length == 1) { if (int.TryParse(parameters[0], out result) && Convert.ToInt32(parameters[0]) != 0) { var input = result; if (input > 100) { // Max number input = 100; } message = await Context.Channel.GetMessagesAsync(Convert.ToInt32(input)).FlattenAsync(); replyMessage = "Are you sure you want to delete " + input + " lines? [Y/N]"; validReturn = true; } else { await ReplyAsync("Invalid input."); validReturn = false; } } else if (parameters.Length == 2) { if (int.TryParse(parameters[0], out result) && Convert.ToInt32(parameters[0]) != 0) { var input = result; filename = parameters[1]; if (input > 100) { // Max number input = 100; } message = await Context.Channel.GetMessagesAsync(Convert.ToInt32(input)).FlattenAsync(); replyMessage = "Are you sure you want to delete " + input + " lines? [Y/N]"; validReturn = true; withName = true; } else { await ReplyAsync("Invalid input."); validReturn = false; } } else { replyMessage = "Are you sure you want to delete 100 lines? [Y/N]"; validReturn = true; } if (validReturn == true) { // Get the confirmation of the user log.Info("Getting confirmation to delete"); await ReplyAsync(replyMessage); var response = await NextMessageAsync(); AdminCommands ac = new AdminCommands(); log.Debug("Immediately after"); if (ac.GetConfirmation(response.ToString()) == true) { log.Info("Deleting and logging messages..."); FileInteraction fi = new FileInteraction(); List <Messages> msgList = new List <Messages>(); // Make a new list to pass foreach (var item in message) { string lines; if (item.Attachments.Count > 0 && withName == true) { lines = "[" + item.Timestamp + "] " + "(" + item.Channel + ") " + item.Author + ": " + item.Content + "\n<" + item.Attachments.Count + " item(s) attached>"; fi.Logged(lines, filename); } else if (item.Attachments.Count == 0 && withName == true) { lines = "[" + item.Timestamp + "] " + "(" + item.Channel + ") " + item.Author + ": " + item.Content; fi.Logged(lines, filename); } else if (item.Attachments.Count > 0 && withName == false) { lines = "[" + item.Timestamp + "] " + "(" + item.Channel + ") " + item.Author + ": " + item.Content + "\n<" + item.Attachments.Count + " item(s) attached>"; fi.Logged(lines); } else { lines = "[" + item.Timestamp + "] " + "(" + item.Channel + ") " + item.Author + ": " + item.Content; fi.Logged(lines); } if (item.Content.Contains("Deletion log") && item.Author.IsBot == true) { log.Debug("Ignoring bot message"); } else if (item.Author.IsBot == true) { log.Debug("Ignoring bot message"); await item.DeleteAsync(); } else { msgList.Add(new Messages(item.Author.ToString(), item.Timestamp.ToString(), item.Content)); // Add to the list await item.DeleteAsync(); await Task.Delay(100); } } if (withName == true) { string location = @"C:\Users\Amagi\source\repos\EimiBot\EimiBot2\logs\" + fi.GetDate() + "-deletionlogs - " + filename + ".txt"; await Context.Channel.SendFileAsync(location, "Deletion log for " + fi.GetTimestamp() + ": " + filename); } else { string location = @"C:\Users\Amagi\source\repos\EimiBot\EimiBot2\logs\" + fi.GetDate() + "-deletionlogs.txt"; await Context.Channel.SendFileAsync(location, "Deletion log for " + fi.GetTimestamp()); } SheetsInteraction si = new SheetsInteraction(); log.Debug(si.UpdateTab(filename)); log.Debug(si.EditData(msgList)); log.Debug(si.AutoResize(filename)); } else { log.Info("No messages deleted and logged."); await ReplyAsync("Will not delete messages."); } } }