Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.19 KB | None | 0 0
  1. using Discord;
  2. using Discord.Commands;
  3. using Discord.WebSocket;
  4. using Microsoft.Extensions.DependencyInjection;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.IO;
  12.  
  13. namespace Bot
  14. {
  15. public class Program
  16. {
  17. public static void Main(string[] args)
  18. => new Program().MainAsync().GetAwaiter().GetResult();
  19.  
  20. public readonly DiscordSocketClient client;
  21. private readonly IServiceCollection map = new ServiceCollection();
  22. private readonly CommandService commands = new CommandService();
  23. private IServiceProvider services;
  24. private Program()
  25. {
  26. client = new DiscordSocketClient(new DiscordSocketConfig
  27. {
  28. LogLevel = LogSeverity.Debug,
  29. });
  30. client.Log += Log;
  31. commands.Log += Log;
  32.  
  33. }
  34.  
  35. private async Task MainAsync()
  36. {
  37. await commands.AddModuleAsync<HERE>();
  38. await commands.AddModuleAsync<HI>();
  39. await commands.AddModuleAsync<Date>();
  40. await commands.AddModuleAsync<Spam>();
  41. await commands.AddModuleAsync<Calculatrice>();
  42. await commands.AddModuleAsync<Sommaire>();
  43. await commands.AddModuleAsync<Image>();
  44. await commands.AddModuleAsync<De>();
  45. await commands.AddModuleAsync<Exposant>();
  46. await commands.AddModuleAsync<Files>();
  47. await commands.AddModuleAsync<Files2>();
  48.  
  49. client.MessageReceived += HandleCommandAsync;
  50. await client.LoginAsync(TokenType.Bot, "MzcyNzQ5Nzk5NDUzMzYwMTM5.DVdixA.sqppWEcY_kxLTRkJhSW2CAEKqCM");
  51. await client.StartAsync();
  52. await Task.Delay(-1);
  53. //client.
  54.  
  55.  
  56. }
  57.  
  58. public async Task HandleCommandAsync(SocketMessage arg)
  59. {
  60. var msg = arg as SocketUserMessage;
  61. if (msg == null) return;
  62. int pos = 0;
  63.  
  64. if (msg.HasMentionPrefix(client.CurrentUser, ref pos))
  65. {
  66. var context = new SocketCommandContext(client, msg);
  67. var result = await commands.ExecuteAsync(context, pos, services);
  68. }
  69. var Context = new SocketCommandContext(client, msg);
  70. Console.WriteLine(msg);
  71. string path = @"C:\Users\Benoi\source\repos\ConsoleApp1\ConsoleApp1\Save.txt";
  72. string appendText = "msg:" + msg.Content + ":Id:" + msg.Id + ":Nom:" + msg.Author +":Date:" + msg.CreatedAt + Environment.NewLine;
  73. File.AppendAllText(path, appendText);
  74.  
  75. //if (Context.User.Id != 372749799453360139 && (msg.Channel.Id == 409726621470162954 || msg.Channel.Id == 409400005267554304)) { await msg.Channel.SendMessageAsync("Its done"); }
  76. }
  77.  
  78.  
  79. private Task Log(LogMessage msg)
  80. {
  81. var cc = Console.ForegroundColor;
  82. switch (msg.Severity)
  83. {
  84. case LogSeverity.Critical:
  85. Console.ForegroundColor = ConsoleColor.DarkRed;
  86. break;
  87. case LogSeverity.Error:
  88. Console.ForegroundColor = ConsoleColor.Red;
  89. break;
  90. case LogSeverity.Warning:
  91. Console.ForegroundColor = ConsoleColor.DarkYellow;
  92. break;
  93. case LogSeverity.Info:
  94. Console.ForegroundColor = ConsoleColor.White;
  95. break;
  96. case LogSeverity.Verbose:
  97. Console.ForegroundColor = ConsoleColor.Green;
  98. break;
  99. case LogSeverity.Debug:
  100. Console.ForegroundColor = ConsoleColor.DarkGray;
  101. break;
  102. }
  103. Console.WriteLine(msg);
  104. Console.ForegroundColor = cc;
  105. return Task.CompletedTask;
  106. }
  107. }
  108. public class Sommaire : ModuleBase
  109. {
  110. [Command("Module"), Summary("Calcul +-")]
  111. public async Task SayModule()
  112. {
  113. await ReplyAsync("-Here ?");
  114. await ReplyAsync("-Hi");
  115. await ReplyAsync("-Date");
  116. await ReplyAsync("-Spam");
  117. await ReplyAsync("-Calcul");
  118. await ReplyAsync("-Image");
  119. }
  120. }
  121. public class HERE : ModuleBase
  122. {
  123. [Command("Here ?"), Summary("Answer with Hi")]
  124. public async Task SayHi()
  125. {
  126. await ReplyAsync("zzZ");
  127. }
  128. }
  129. public class HI : ModuleBase
  130. {
  131. [Command("Hi"), Summary("Answer with Hi")]
  132. public async Task SayHi()
  133. {
  134. await ReplyAsync("Hi!");
  135. }
  136. }
  137. public class Date : ModuleBase
  138. {
  139. [Command("Date"), Summary("Donne la date")]
  140. public async Task SayDate()
  141. {
  142. DateTime dates = DateTime.Now;
  143. String d = dates.ToString();
  144. await ReplyAsync("On est le " + d);
  145. }
  146. }
  147. public class Spam : ModuleBase
  148. {
  149. [Command("Spam"), Summary("Donne la date")]
  150. public async Task SayDate()
  151. {
  152. int a = 0;
  153. while (a != 5) { await ReplyAsync("Osef"); a = a + 1; }
  154. }
  155. }
  156. public class Calculatrice : ModuleBase
  157. {
  158. [Command("Calcul"), Summary("Renvoie le resultat")]
  159. public async Task SayResult(string arg)
  160. {
  161. if(arg.Contains("+") == true) {
  162. string[] calcul = arg.Split('+');
  163. int resultats = Int32.Parse(arg);
  164. await ReplyAsync(resultats.ToString());
  165. int i;
  166. int resultat = 0;
  167. for (i = 0; i < calcul.Length; i++)
  168. { resultat = resultat + Int32.Parse(calcul[i]); }
  169.  
  170. if (resultat > -214748364 && resultat < 2147483647) { await ReplyAsync(resultat.ToString()); }
  171. else { await ReplyAsync("I can't do this, i'm only in 32 bit"); }
  172.  
  173. }
  174. }
  175. }
  176. public class Image : ModuleBase
  177. {
  178. [Command("Image"), Summary("Envoie une image")]
  179. public async Task DispImage()
  180. {
  181. await ReplyAsync("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRLxmBuSqBLEVe6FZkt8CK7GxewFiDHOihhgod4ncC8H0hPVV6w");
  182. }
  183. }
  184. public class De : ModuleBase
  185. {
  186. [Command("De"), Summary("Envoie une image")]
  187. public async Task Dispde()
  188. {
  189. Random de = new Random();
  190. int b = de.Next(2);
  191. await ReplyAsync(b.ToString());
  192. }
  193. }
  194. public class Exposant : ModuleBase
  195. {
  196. [Command("exp"), Summary("Renvoie le resultat d'un exposant")]
  197. public async Task Dispexp(int arg, int arg2)
  198. {
  199. int resultat = arg;
  200. for (int i = 1; i < arg2; i++)
  201. {
  202. resultat = resultat * arg;
  203. }
  204. await ReplyAsync(resultat.ToString());
  205. }
  206. }
  207. public class Files : ModuleBase
  208. {
  209. [Command("F"), Summary("Recup des données")]
  210. public async Task Recupfile()
  211. {
  212. string path = @"C:\Users\Benoi\source\repos\ConsoleApp1\ConsoleApp1\Save.txt";
  213. string appendText = "This is extra text" + Environment.NewLine;
  214. File.AppendAllText(path, appendText);
  215. await ReplyAsync("Its done");
  216. //await ReplyAsync("<@372749799453360139> r");
  217. //Context.
  218. //File.WriteAllText //AppendAllText
  219. //delay
  220. }
  221. }
  222. public class Files2 : ModuleBase
  223. {
  224. [Command("user"), Summary("Recup des données")]
  225. public async Task Recupfile()
  226. {
  227. //ulong id = Context.User.Id;
  228. //await ReplyAsync(id.ToString());
  229. string message = Context.Message.Content;
  230. message = message.Remove(0,22);
  231. Console.WriteLine(message);
  232. //await ReplyAsync(message);
  233.  
  234. //Context.
  235. //File.WriteAllText //AppendAllText
  236. //delay
  237. }
  238. }
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement