diff --git a/Dedsec/Commands.cs b/Dedsec/Commands.cs new file mode 100644 index 0000000..e051961 --- /dev/null +++ b/Dedsec/Commands.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Discord; +using Discord.Commands; +using Discord.WebSocket; +using System.Timers; + +namespace _10minstut.Modules +{ + + public class Commands : ModuleBase + { + public static Timer SitTimer; + public static Timer SleepTimer; + + public async void sit_straight_reminder(object obj, ElapsedEventArgs e) + { + await ReplyAsync("Sit Straight, you don't want your back to pain when you get old do you?"); + } + + public async void water_reminder(object obj, ElapsedEventArgs e) + { + await ReplyAsync("Drink water, you don't want kidney stones do you? "); + } + + [Command("Sit")] + + public async Task sitTimer() + { + await ReplyAsync("Okay,I will remind you in 15 minutes!"); + System.Timers.Timer SitTimer = new System.Timers.Timer(); + SitTimer.Elapsed += new ElapsedEventHandler(sit_straight_reminder); + SitTimer.Interval = 900000; + SitTimer.Enabled = true; + SitTimer.AutoReset = true; + } + + [Command("Water")] + + public async Task water() + { + await ReplyAsync("Okay,I will remind you in 30 minutes!"); + System.Timers.Timer SleepTimer = new System.Timers.Timer(); + SleepTimer.Elapsed += new ElapsedEventHandler(water_reminder); + SleepTimer.Interval = 1800000; + SleepTimer.Enabled = true; + SleepTimer.AutoReset = true; + } + + + } + + + + + + +} diff --git a/Dedsec/Dedsec.docx b/Dedsec/Dedsec.docx new file mode 100644 index 0000000..d47910d Binary files /dev/null and b/Dedsec/Dedsec.docx differ diff --git a/Dedsec/Dedsec.pptx b/Dedsec/Dedsec.pptx new file mode 100644 index 0000000..53cfb95 Binary files /dev/null and b/Dedsec/Dedsec.pptx differ diff --git a/Dedsec/Program.cs b/Dedsec/Program.cs new file mode 100644 index 0000000..6c3ec4a --- /dev/null +++ b/Dedsec/Program.cs @@ -0,0 +1,93 @@ +using System; +using System.Reflection; +using System.Threading.Tasks; +using Discord; +using Discord.Commands; +using Discord.WebSocket; +using Microsoft.Extensions.DependencyInjection; + +namespace _10minstut +{ + class Program + { + static void Main(string[] args) => new Program().RunBotAsync().GetAwaiter().GetResult(); + public String time; + public String time_1; + private DiscordSocketClient _client; + private CommandService _commands; + private IServiceProvider _services; + + public async Task RunBotAsync() + { + _client = new DiscordSocketClient(); + _commands = new CommandService(); + _services = new ServiceCollection() + .AddSingleton(_client) + .AddSingleton(_commands) + .BuildServiceProvider(); + + + + string token = "TOKEN FOR THE BOT"; + + _client.Log += _client_Log; + + await RegisterCommandsAsync(); + + await _client.LoginAsync(TokenType.Bot, token); + + await _client.StartAsync(); + + await Task.Delay(-1); + + } + + private Task _client_Log(LogMessage arg) + { + Console.WriteLine(arg); + return Task.CompletedTask; + } + + public async Task RegisterCommandsAsync() + { + _client.MessageReceived += HandleCommandAsync; + await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _services); + } + + + + private async Task HandleCommandAsync(SocketMessage arg) + { + var message = arg as SocketUserMessage; + var context = new SocketCommandContext(_client, message); + if (message.Author.IsBot) return; + + int argPos = 0; + if (message.HasStringPrefix("*", ref argPos)) + { + var result = await _commands.ExecuteAsync(context, argPos, _services); + if (!result.IsSuccess) Console.WriteLine(result.ErrorReason); + if (result.Error.Equals(CommandError.UnmetPrecondition)) await message.Channel.SendMessageAsync(result.ErrorReason); + } + + + + if (arg.Content.StartsWith("*Sleep")) + { + time = arg.Content.ToLower(); + time_1 = time.Replace("*sleep", ""); + await arg.Channel.SendMessageAsync("I will remind you in " + time_1 + " minutes!"); + Console.WriteLine(time_1); + int time_int = int.Parse(time_1); + + time_int *= 60000; + System.Threading.Thread.Sleep(time_int); + + await arg.Channel.SendMessageAsync(arg.Author.Mention + " Sleep,Wasn't that your last game?"); + + } + + } + + } +} diff --git a/Dedsec/readme.md b/Dedsec/readme.md new file mode 100644 index 0000000..cd16c87 --- /dev/null +++ b/Dedsec/readme.md @@ -0,0 +1,6 @@ +Asterix - Discord Bot + +A simple discord bot which has the following commands: +1.Sit: It will remind you to sit straight while gaming every 15 minutes. +2.Sleep: It will remind you to sleep after a specific amount of time which you can set. +3.Water: It will remind you to drink water while gaming every 30 minutes.