Added QC Search, and fixed a few things with Guild Settings in regards to prefix usage, and bot boot up.
This commit is contained in:
1 parent
716ca9bf5e
commit
b94573353d
3 files changed
+88
-15
No files matched your search
@@ -30,10 +30,35 @@ namespace StarsiegeBot
|
||||
public BotSettings()
|
||||
{
|
||||
Console.WriteLine("Bot Setting Commands Loaded");
|
||||
if (!File.Exists("guildSettings.json"))
|
||||
{
|
||||
Console.Write("Guild Settings Config File Not Found. Creating One...");
|
||||
GuildSettings item = new GuildSettings();
|
||||
item.UseAutoRoles = false;
|
||||
item.UseGlobalPrefix = true;
|
||||
item.UseLevelRoles = false;
|
||||
item.UseLevels = false;
|
||||
item.UseSelfRoles = false;
|
||||
item.AllowRolesPurchase = false;
|
||||
item.UseAutoRoles = false;
|
||||
item.LevelRoles = new Dictionary<string, int>();
|
||||
item.Prefixes = new List<string>();
|
||||
item.SelfRoles = new Dictionary<string, int>();
|
||||
item.Prefixes.Add(">");
|
||||
// this line... is a test line.
|
||||
|
||||
GuildSettings = new Dictionary<string, GuildSettings>();
|
||||
GuildSettings.Add("default", item);
|
||||
|
||||
string output = JsonConvert.SerializeObject(GuildSettings);
|
||||
File.WriteAllTextAsync("guildSettings.json", output);
|
||||
Console.WriteLine(" Done!");
|
||||
}
|
||||
var json = "";
|
||||
using (var fs = File.OpenRead("guildSettings.json"))
|
||||
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
|
||||
json = sr.ReadToEnd();
|
||||
|
||||
GuildSettings = JsonConvert.DeserializeObject<Dictionary<string, GuildSettings>>(json);
|
||||
}
|
||||
|
||||
@@ -80,7 +105,8 @@ namespace StarsiegeBot
|
||||
public async Task RemovePrefix (CommandContext ctx, string prefix)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
|
||||
GuildSettings.Remove(prefix);
|
||||
await ctx.RespondAsync($"Removed `{prefix}` as a command prefix.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+49
-12
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -29,11 +30,6 @@ namespace StarsiegeBot
|
||||
|
||||
protected string BotName { get; set; }
|
||||
|
||||
public Program()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private async Task StartTimer(CancellationToken cancellationToken)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
@@ -41,8 +37,7 @@ namespace StarsiegeBot
|
||||
while (true)
|
||||
{
|
||||
string output = JsonConvert.SerializeObject(BotSettings.GuildSettings);
|
||||
await File.WriteAllTextAsync("GuildSettings.json", output);
|
||||
Console.WriteLine("Wrote new info to file.");
|
||||
await File.WriteAllTextAsync("guildSettings.json", output);
|
||||
await Task.Delay(TimeSpan.FromSeconds(120), cancellationToken);
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
@@ -69,7 +64,7 @@ namespace StarsiegeBot
|
||||
if (args.Length > 0)
|
||||
BotName = args[0].ToLower();
|
||||
else
|
||||
BotName = "cybrid";
|
||||
BotName = "ssp";
|
||||
|
||||
BotEventId = new EventId(276, BotName);
|
||||
}
|
||||
@@ -205,13 +200,36 @@ namespace StarsiegeBot
|
||||
{
|
||||
d.Logger.LogDebug(BotEventId, "Event_MessageCreated.");
|
||||
|
||||
var cnext = d.GetCommandsNext();
|
||||
var msg = e.Message;
|
||||
CommandsNextExtension cnext = d.GetCommandsNext();
|
||||
DiscordMessage msg = e.Message;
|
||||
|
||||
// Check if message has valid prefix.
|
||||
// json file loaded...
|
||||
var cmdStart = msg.GetStringPrefixLength("!");
|
||||
BotSettings.GuildSettings.ContainsKey(e.Guild.Id.ToString());
|
||||
int cmdStart = msg.GetStringPrefixLength("!");
|
||||
|
||||
string gId = e.Guild.Id.ToString();
|
||||
List<string> prefixes = BotSettings.GuildSettings["default"].Prefixes;
|
||||
// Check to see if the guild has settings.
|
||||
if (BotSettings.GuildSettings.ContainsKey(gId))
|
||||
{
|
||||
// see if the guild wants global prefixes.
|
||||
if (BotSettings.GuildSettings[gId].UseGlobalPrefix)
|
||||
{
|
||||
prefixes = prefixes.Concat(BotSettings.GuildSettings[gId].Prefixes).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
prefixes = BotSettings.GuildSettings[gId].Prefixes;
|
||||
}
|
||||
}
|
||||
|
||||
// check each prefix. break on the one that is evoked.
|
||||
foreach (string item in prefixes)
|
||||
{
|
||||
cmdStart = msg.GetStringPrefixLength(item);
|
||||
if (cmdStart != -1) break;
|
||||
}
|
||||
// we didn't find a command prefix... Break.
|
||||
if (cmdStart == -1) return Task.CompletedTask;
|
||||
|
||||
// Retrieve prefix.
|
||||
@@ -323,6 +341,25 @@ namespace StarsiegeBot
|
||||
}
|
||||
private Task Event_GuildAvailable(DiscordClient d, GuildCreateEventArgs e)
|
||||
{
|
||||
string gId = e.Guild.Id.ToString();
|
||||
if (!BotSettings.GuildSettings.ContainsKey(gId))
|
||||
{
|
||||
Console.WriteLine("making config");
|
||||
GuildSettings item = new GuildSettings();
|
||||
item.UseAutoRoles = false;
|
||||
item.UseGlobalPrefix = true;
|
||||
item.UseLevelRoles = false;
|
||||
item.UseLevels = false;
|
||||
item.UseSelfRoles = false;
|
||||
item.AllowRolesPurchase = false;
|
||||
item.UseAutoRoles = false;
|
||||
item.LevelRoles = new Dictionary<string, int>();
|
||||
item.Prefixes = new List<string>();
|
||||
item.SelfRoles = new Dictionary<string, int>();
|
||||
item.Prefixes.Add(">");
|
||||
// this line... is a test line.
|
||||
BotSettings.GuildSettings.Add(gId, item);
|
||||
}
|
||||
// let's log the name of the guild that was just
|
||||
// sent to our client
|
||||
d.Logger.LogInformation(BotEventId, $"Guild available: {e.Guild.Name}");
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace StarsiegeBot
|
||||
{
|
||||
int idnum = rnd.Next(Quickchats.Count);
|
||||
chat = Quickchats[idnum];
|
||||
msg.Content = idnum + ": " + chat.text;
|
||||
msg.Content = $"[{idnum}] " + chat.text;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -110,10 +110,20 @@ namespace StarsiegeBot
|
||||
public async Task SearchQuickChats(CommandContext ctx, [RemainingText] string toSearch)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
DiscordMessageBuilder msg = new DiscordMessageBuilder();
|
||||
msg.Content = "";
|
||||
for (int i = 0; i < Quickchats.Count; i++)
|
||||
{
|
||||
|
||||
if (Quickchats[i].text.ToLower().Contains(toSearch.ToLower()))
|
||||
{
|
||||
msg.Content += $"[{i}] {Quickchats[i].text}\r\n";
|
||||
}
|
||||
}
|
||||
if (msg.Content == "")
|
||||
{
|
||||
msg.Content = "No results found.";
|
||||
}
|
||||
await ctx.RespondAsync(msg);
|
||||
}
|
||||
}
|
||||
public class Quickchats
|
||||
|
||||
Reference in new issue
Block a user