Bot test
This commit is contained in:
@@ -4,8 +4,7 @@ using DSharpPlus.CommandsNext.Attributes;
|
|||||||
|
|
||||||
namespace LaDOSE.DiscordBot.Command
|
namespace LaDOSE.DiscordBot.Command
|
||||||
{
|
{
|
||||||
public partial class Twitch
|
|
||||||
{
|
|
||||||
internal class Result
|
internal class Result
|
||||||
{
|
{
|
||||||
Dependencies dep;
|
Dependencies dep;
|
||||||
@@ -32,5 +31,5 @@ namespace LaDOSE.DiscordBot.Command
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ using DSharpPlus.CommandsNext.Attributes;
|
|||||||
namespace LaDOSE.DiscordBot.Command
|
namespace LaDOSE.DiscordBot.Command
|
||||||
{
|
{
|
||||||
[RequireRolesAttribute("SuperAdmin")]
|
[RequireRolesAttribute("SuperAdmin")]
|
||||||
internal class Shutdown
|
public class Shutdown
|
||||||
{
|
{
|
||||||
private readonly Dependencies dep;
|
private readonly Dependencies dep;
|
||||||
|
|
||||||
@@ -15,7 +15,6 @@ namespace LaDOSE.DiscordBot.Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Command("shutdown")]
|
[Command("shutdown")]
|
||||||
public async Task ShutDownAsync(CommandContext ctx)
|
public async Task ShutDownAsync(CommandContext ctx)
|
||||||
{
|
{
|
||||||
|
|||||||
41
LaDOSE.Src/LaDOSE.DiscordBot/Command/Todo.cs
Normal file
41
LaDOSE.Src/LaDOSE.DiscordBot/Command/Todo.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using DSharpPlus.CommandsNext;
|
||||||
|
using DSharpPlus.CommandsNext.Attributes;
|
||||||
|
|
||||||
|
namespace LaDOSE.DiscordBot.Command
|
||||||
|
{
|
||||||
|
public class Todo
|
||||||
|
{
|
||||||
|
private readonly Dependencies dep;
|
||||||
|
|
||||||
|
public Todo(Dependencies d)
|
||||||
|
{
|
||||||
|
dep = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("todo")]
|
||||||
|
public async Task TwitchAsync(CommandContext ctx, string command,params string[] todo)
|
||||||
|
{
|
||||||
|
await ctx.TriggerTypingAsync();
|
||||||
|
switch (command.ToUpperInvariant())
|
||||||
|
{
|
||||||
|
case "ADD":
|
||||||
|
dep.TodoService.Add(todo[0]);
|
||||||
|
break;
|
||||||
|
case "LIST":
|
||||||
|
await ctx.RespondAsync($"{dep.TodoService.List()}");
|
||||||
|
break;
|
||||||
|
case "DEL":
|
||||||
|
int id;
|
||||||
|
if (int.TryParse(todo[0], out id))
|
||||||
|
{
|
||||||
|
await ctx.RespondAsync($"{dep.TodoService.Delete(id)}");
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
await ctx.RespondAsync($"invalid id");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
await ctx.RespondAsync($"command : {command}, todo: {todo} ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,23 +4,19 @@ using DSharpPlus.CommandsNext.Attributes;
|
|||||||
|
|
||||||
namespace LaDOSE.DiscordBot.Command
|
namespace LaDOSE.DiscordBot.Command
|
||||||
{
|
{
|
||||||
public class Result
|
public class Twitch
|
||||||
{
|
{
|
||||||
|
private readonly Dependencies dep;
|
||||||
|
|
||||||
internal class Twitch
|
public Twitch(Dependencies d)
|
||||||
{
|
{
|
||||||
Dependencies dep;
|
dep = d;
|
||||||
public Twitch(Dependencies d)
|
}
|
||||||
{
|
|
||||||
this.dep = d;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Command("twitch")]
|
[Command("twitch")]
|
||||||
public async Task TwitchAsync(CommandContext ctx)
|
public async Task TwitchAsync(CommandContext ctx)
|
||||||
{
|
{
|
||||||
await ctx.RespondAsync("https://www.twitch.tv/LaDOSETV");
|
await ctx.RespondAsync("https://www.twitch.tv/LaDOSETV");
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,12 @@ using LaDOSE.DiscordBot.Service;
|
|||||||
|
|
||||||
namespace LaDOSE.DiscordBot
|
namespace LaDOSE.DiscordBot
|
||||||
{
|
{
|
||||||
internal class Dependencies
|
public class Dependencies
|
||||||
{
|
{
|
||||||
internal InteractivityModule Interactivity { get; set; }
|
internal InteractivityModule Interactivity { get; set; }
|
||||||
internal CancellationTokenSource Cts { get; set; }
|
internal CancellationTokenSource Cts { get; set; }
|
||||||
public ChallongeService ChallongeService { get; set; }
|
public ChallongeService ChallongeService { get; set; }
|
||||||
|
public TodoService TodoService { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,6 +44,7 @@ namespace LaDOSE.DiscordBot
|
|||||||
|
|
||||||
|
|
||||||
var challongeService = new ChallongeService(challongeToken);
|
var challongeService = new ChallongeService(challongeToken);
|
||||||
|
var todoService = new TodoService();
|
||||||
var cts = new CancellationTokenSource();
|
var cts = new CancellationTokenSource();
|
||||||
DependencyCollection dep = null;
|
DependencyCollection dep = null;
|
||||||
|
|
||||||
@@ -53,7 +54,8 @@ namespace LaDOSE.DiscordBot
|
|||||||
{
|
{
|
||||||
|
|
||||||
Cts = cts,
|
Cts = cts,
|
||||||
ChallongeService = challongeService
|
ChallongeService = challongeService,
|
||||||
|
TodoService = todoService,
|
||||||
});
|
});
|
||||||
dep = d.Build();
|
dep = d.Build();
|
||||||
}
|
}
|
||||||
@@ -72,6 +74,7 @@ namespace LaDOSE.DiscordBot
|
|||||||
_cnext.RegisterCommands<Result>();
|
_cnext.RegisterCommands<Result>();
|
||||||
_cnext.RegisterCommands<Twitch>();
|
_cnext.RegisterCommands<Twitch>();
|
||||||
_cnext.RegisterCommands<Shutdown>();
|
_cnext.RegisterCommands<Shutdown>();
|
||||||
|
_cnext.RegisterCommands<Todo>();
|
||||||
|
|
||||||
|
|
||||||
//discord.MessageCreated += async e =>
|
//discord.MessageCreated += async e =>
|
||||||
|
|||||||
60
LaDOSE.Src/LaDOSE.DiscordBot/Service/TodoService.cs
Normal file
60
LaDOSE.Src/LaDOSE.DiscordBot/Service/TodoService.cs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace LaDOSE.DiscordBot.Service
|
||||||
|
{
|
||||||
|
public class TodoService
|
||||||
|
{
|
||||||
|
private const string db = "todo.txt";
|
||||||
|
|
||||||
|
public TodoService()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Add(string text)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(text)) {
|
||||||
|
using (var textWriter =File.AppendText(db))
|
||||||
|
{
|
||||||
|
textWriter.WriteLine(text);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
public bool Delete(int id)
|
||||||
|
{
|
||||||
|
string returnText = "";
|
||||||
|
var text = File.ReadAllText(db);
|
||||||
|
var i = 0;
|
||||||
|
foreach (var line in text.Split('\n'))
|
||||||
|
{
|
||||||
|
++i;
|
||||||
|
if (i != id)
|
||||||
|
{
|
||||||
|
returnText += $"{line}\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
File.WriteAllText(db,returnText);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public string List()
|
||||||
|
{
|
||||||
|
string returnText = "";
|
||||||
|
var text = File.ReadAllText(db);
|
||||||
|
var i = 0;
|
||||||
|
foreach (var line in text.Split('\n'))
|
||||||
|
{
|
||||||
|
if(!string.IsNullOrEmpty(line))
|
||||||
|
returnText += $"{++i}. {line}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user