Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@OMGasm
Last active February 1, 2017 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OMGasm/2d97f0479fb512b6096d81e3955b3148 to your computer and use it in GitHub Desktop.
Save OMGasm/2d97f0479fb512b6096d81e3955b3148 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
/// <summary>
/// as the namespace implies, THIS IS A SHIT BOT
/// please do not think this is anything more than a lazy half-assed attempt to attach embeds
///
/// please, for your own sake, don't use this as an example for a bot, as it's just a testbed of shit 😂
///
/// </summary>
namespace shitbot3000
{
public class Program : ModuleBase
{
Random r = new Random();
Regex rx = new Regex(@"^https?:\/\/.+?\/.+?\.(png|jpe?g|gif)\??((?! ).)*$", RegexOptions.Compiled);
static void Main(string[] args) => new Program().Run().GetAwaiter().GetResult();
async Task Run()
{
DiscordSocketConfig clientcfg = new DiscordSocketConfig()
{
AlwaysDownloadUsers = false,
LargeThreshold = 0,
};
DiscordSocketClient client = new DiscordSocketClient(clientcfg);
DependencyMap map = new DependencyMap();
map.Add(client);
CommandService commands = new CommandService();
client.MessageReceived += async x =>
{
var msg = x as SocketUserMessage;
if (msg == null) return;
if (msg.Author.Id != client.CurrentUser.Id) return;
int pos = 0;
if (!(msg.HasStringPrefix(@"\|", ref pos))) return;
var context = new CommandContext(client, msg);
var result = await commands.ExecuteAsync(context, pos, map);
if (!result.IsSuccess)
await context.Channel.SendMessageAsync(result.ErrorReason);
};
client.Log += async x =>
{
switch (x.Severity)
{
case LogSeverity.Critical:
case LogSeverity.Error:
Console.ForegroundColor = ConsoleColor.Red;
break;
case LogSeverity.Warning:
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case LogSeverity.Info:
case LogSeverity.Verbose:
Console.ForegroundColor = ConsoleColor.DarkGray;
break;
case LogSeverity.Debug:
return;
}
Console.WriteLine($"{DateTime.UtcNow.ToString("dd/MM/yyyy H:mm:ss")} {x}");
await Task.Delay(0);
};
await commands.AddModulesAsync(Assembly.GetEntryAssembly());
await client.LoginAsync(TokenType.User, @"REDACTED, MOTHER FUCKERS'); DROP TABLE tokens;-- ");
await client.ConnectAsync();
await Task.Delay(-1);
}
[Command("em")]
public async Task embed([Remainder]string s)
{
EmbedBuilder em = new EmbedBuilder();
em.Color = new Color((uint)r.Next(16777216));
if (rx.IsMatch(s))
{
em.Title = "[🔗]";
em.Url = s;
em.ImageUrl = s;
}
else
{
em.Author = new EmbedAuthorBuilder();
em.Author.IconUrl = Context.User.AvatarUrl;
em.Author.Name = $"{ ((Context.User as IGuildUser)?.Nickname ?? Context.User.Username)} 👀";
em.Title = "";
em.Description = s;
}
await Context.Message.ModifyAsync(x =>
{
x.Content = "";
x.Embed = em.Build();
});
}
[Command("q")]
public async Task quote(ulong m)
{
var msg = (await Context.Channel.GetMessagesAsync(Context.Message, Direction.Before).Flatten())
.First(x => x.Id == m);
if (msg == null) return;
var attachment = msg.Attachments.FirstOrDefault();
var embed = msg.Embeds.FirstOrDefault();
var em = new EmbedBuilder()
.WithAuthor(new EmbedAuthorBuilder()
.WithName((msg.Author as IGuildUser)?.Nickname ?? msg.Author.Username)
.WithIconUrl(msg.Author.AvatarUrl))
.WithColor(new Color((byte)(255 - r.Next(56)), (byte)(255 - r.Next(56)), (byte)(255 - r.Next(56))))
.WithDescription(msg.Content)
.WithImageUrl(attachment?.Url ?? embed?.Image?.Url ?? embed?.Thumbnail?.ProxyUrl)
.WithTimestamp(msg.EditedTimestamp ?? msg.Timestamp);
await Context.Channel.SendMessageAsync("", embed: em);
await Context.Message.DeleteAsync();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment