Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Discord;
- using Discord.Commands;
- using Discord.WebSocket;
- using Microsoft.Extensions.DependencyInjection;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace Bot
- {
- public class Program
- {
- public static void Main(string[] args)
- => new Program().MainAsync().GetAwaiter().GetResult();
- public readonly DiscordSocketClient client;
- private readonly IServiceCollection map = new ServiceCollection();
- private readonly CommandService commands = new CommandService();
- private IServiceProvider services;
- private Program()
- {
- client = new DiscordSocketClient(new DiscordSocketConfig
- {
- LogLevel = LogSeverity.Debug,
- });
- client.Log += Log;
- commands.Log += Log;
- }
- private async Task MainAsync()
- {
- await commands.AddModuleAsync<HERE>();
- await commands.AddModuleAsync<HI>();
- await commands.AddModuleAsync<Date>();
- await commands.AddModuleAsync<Spam>();
- await commands.AddModuleAsync<Calculatrice>();
- await commands.AddModuleAsync<Sommaire>();
- await commands.AddModuleAsync<Image>();
- await commands.AddModuleAsync<De>();
- await commands.AddModuleAsync<Exposant>();
- await commands.AddModuleAsync<Files>();
- await commands.AddModuleAsync<Files2>();
- client.MessageReceived += HandleCommandAsync;
- await client.LoginAsync(TokenType.Bot, "MzcyNzQ5Nzk5NDUzMzYwMTM5.DVdixA.sqppWEcY_kxLTRkJhSW2CAEKqCM");
- await client.StartAsync();
- await Task.Delay(-1);
- //client.
- }
- public async Task HandleCommandAsync(SocketMessage arg)
- {
- var msg = arg as SocketUserMessage;
- if (msg == null) return;
- int pos = 0;
- if (msg.HasMentionPrefix(client.CurrentUser, ref pos))
- {
- var context = new SocketCommandContext(client, msg);
- var result = await commands.ExecuteAsync(context, pos, services);
- }
- var Context = new SocketCommandContext(client, msg);
- Console.WriteLine(msg);
- string path = @"C:\Users\Benoi\source\repos\ConsoleApp1\ConsoleApp1\Save.txt";
- string appendText = "msg:" + msg.Content + ":Id:" + msg.Id + ":Nom:" + msg.Author +":Date:" + msg.CreatedAt + Environment.NewLine;
- File.AppendAllText(path, appendText);
- //if (Context.User.Id != 372749799453360139 && (msg.Channel.Id == 409726621470162954 || msg.Channel.Id == 409400005267554304)) { await msg.Channel.SendMessageAsync("Its done"); }
- }
- private Task Log(LogMessage msg)
- {
- var cc = Console.ForegroundColor;
- switch (msg.Severity)
- {
- case LogSeverity.Critical:
- Console.ForegroundColor = ConsoleColor.DarkRed;
- break;
- case LogSeverity.Error:
- Console.ForegroundColor = ConsoleColor.Red;
- break;
- case LogSeverity.Warning:
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- break;
- case LogSeverity.Info:
- Console.ForegroundColor = ConsoleColor.White;
- break;
- case LogSeverity.Verbose:
- Console.ForegroundColor = ConsoleColor.Green;
- break;
- case LogSeverity.Debug:
- Console.ForegroundColor = ConsoleColor.DarkGray;
- break;
- }
- Console.WriteLine(msg);
- Console.ForegroundColor = cc;
- return Task.CompletedTask;
- }
- }
- public class Sommaire : ModuleBase
- {
- [Command("Module"), Summary("Calcul +-")]
- public async Task SayModule()
- {
- await ReplyAsync("-Here ?");
- await ReplyAsync("-Hi");
- await ReplyAsync("-Date");
- await ReplyAsync("-Spam");
- await ReplyAsync("-Calcul");
- await ReplyAsync("-Image");
- }
- }
- public class HERE : ModuleBase
- {
- [Command("Here ?"), Summary("Answer with Hi")]
- public async Task SayHi()
- {
- await ReplyAsync("zzZ");
- }
- }
- public class HI : ModuleBase
- {
- [Command("Hi"), Summary("Answer with Hi")]
- public async Task SayHi()
- {
- await ReplyAsync("Hi!");
- }
- }
- public class Date : ModuleBase
- {
- [Command("Date"), Summary("Donne la date")]
- public async Task SayDate()
- {
- DateTime dates = DateTime.Now;
- String d = dates.ToString();
- await ReplyAsync("On est le " + d);
- }
- }
- public class Spam : ModuleBase
- {
- [Command("Spam"), Summary("Donne la date")]
- public async Task SayDate()
- {
- int a = 0;
- while (a != 5) { await ReplyAsync("Osef"); a = a + 1; }
- }
- }
- public class Calculatrice : ModuleBase
- {
- [Command("Calcul"), Summary("Renvoie le resultat")]
- public async Task SayResult(string arg)
- {
- if(arg.Contains("+") == true) {
- string[] calcul = arg.Split('+');
- int resultats = Int32.Parse(arg);
- await ReplyAsync(resultats.ToString());
- int i;
- int resultat = 0;
- for (i = 0; i < calcul.Length; i++)
- { resultat = resultat + Int32.Parse(calcul[i]); }
- if (resultat > -214748364 && resultat < 2147483647) { await ReplyAsync(resultat.ToString()); }
- else { await ReplyAsync("I can't do this, i'm only in 32 bit"); }
- }
- }
- }
- public class Image : ModuleBase
- {
- [Command("Image"), Summary("Envoie une image")]
- public async Task DispImage()
- {
- await ReplyAsync("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRLxmBuSqBLEVe6FZkt8CK7GxewFiDHOihhgod4ncC8H0hPVV6w");
- }
- }
- public class De : ModuleBase
- {
- [Command("De"), Summary("Envoie une image")]
- public async Task Dispde()
- {
- Random de = new Random();
- int b = de.Next(2);
- await ReplyAsync(b.ToString());
- }
- }
- public class Exposant : ModuleBase
- {
- [Command("exp"), Summary("Renvoie le resultat d'un exposant")]
- public async Task Dispexp(int arg, int arg2)
- {
- int resultat = arg;
- for (int i = 1; i < arg2; i++)
- {
- resultat = resultat * arg;
- }
- await ReplyAsync(resultat.ToString());
- }
- }
- public class Files : ModuleBase
- {
- [Command("F"), Summary("Recup des données")]
- public async Task Recupfile()
- {
- string path = @"C:\Users\Benoi\source\repos\ConsoleApp1\ConsoleApp1\Save.txt";
- string appendText = "This is extra text" + Environment.NewLine;
- File.AppendAllText(path, appendText);
- await ReplyAsync("Its done");
- //await ReplyAsync("<@372749799453360139> r");
- //Context.
- //File.WriteAllText //AppendAllText
- //delay
- }
- }
- public class Files2 : ModuleBase
- {
- [Command("user"), Summary("Recup des données")]
- public async Task Recupfile()
- {
- //ulong id = Context.User.Id;
- //await ReplyAsync(id.ToString());
- string message = Context.Message.Content;
- message = message.Remove(0,22);
- Console.WriteLine(message);
- //await ReplyAsync(message);
- //Context.
- //File.WriteAllText //AppendAllText
- //delay
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement