Exemple #1
0
        public async Task <TaskResult <ulong> > PostMessage(PlanetMessage msg)
        {
            //ClientMessage msg = JsonConvert.DeserializeObject<ClientMessage>(json);

            if (msg == null)
            {
                return(new TaskResult <ulong>(false, "Malformed message.", 0));
            }

            ulong channel_id = msg.ChannelId;

            PlanetChatChannel channel = await Context.PlanetChatChannels.FindAsync(channel_id);

            // Get index for message
            ulong index = channel.Message_Count;

            // Update message count. May have to queue this in the future to prevent concurrency issues.
            channel.Message_Count += 1;
            await Context.SaveChangesAsync();

            msg.Index = index;

            string json = JsonConvert.SerializeObject(msg);

            await MessageHub.Current.Clients.Group(channel_id.ToString()).SendAsync("Relay", json);

            return(new TaskResult <ulong>(true, $"Posted message {msg.Index}.", index));
        }
Exemple #2
0
        public async Task <TaskResult> PostMessage(PlanetMessage msg, string token)
        {
            AuthToken authToken = await Context.AuthTokens.FindAsync(token);

            // Return the same if the token is for the wrong user to prevent someone
            // from knowing if they cracked another user's token. This is basically
            // impossible to happen by chance but better safe than sorry in the case that
            // the literal impossible odds occur, more likely someone gets a stolen token
            // but is not aware of the owner but I'll shut up now - Spike
            if (authToken == null || authToken.User_Id != msg.Author_Id)
            {
                return(new TaskResult(false, "Failed to authorize user."));
            }

            //ClientMessage msg = JsonConvert.DeserializeObject<ClientMessage>(json);

            if (msg == null)
            {
                return(new TaskResult(false, "Malformed message."));
            }

            // Stop people from sending insanely large messages
            if (msg.Content.Length > 2048)
            {
                return(new TaskResult(false, "Message is longer than 2048 chars."));
            }

            // Media proxy layer
            msg.Content = await MSPManager.HandleUrls(msg.Content);

            PlanetMessageWorker.AddToQueue(msg);

            return(new TaskResult(true, "Added message to post queue."));
        }
Exemple #3
0
        public static async Task OnRelay(string data)
        {
            PlanetMessage  message = JsonConvert.DeserializeObject <PlanetMessage>(data);
            CommandContext ctx     = new CommandContext();
            await ctx.Set(message);

            await EventService.OnMessage(ctx);

            // check to see if message has a command in it

            if (message.Content.Substring(0, 1) == BotPrefix)
            {
                // get clean command string

                string commandstring = message.Content.Replace(BotPrefix, "");

                // get args

                List <string> args = commandstring.Split(" ").ToList();
                args.RemoveAt(0);

                // get command

                string commandname = message.Content.Split(" ")[0].Replace(BotPrefix, "").ToLower();

                CommandInfo command = CommandService.RunCommandString(commandname, args, ctx);

                if (command != null)
                {
                    command.Method.Invoke(command.moduleInfo.Instance, command.ConvertStringArgs(args, ctx).ToArray());
                }
            }
        }
Exemple #4
0
        public async Task Set(PlanetMessage msg)
        {
            Planet = await Cache.GetPlanet(msg.Planet_Id);

            Channel = await Cache.GetPlanetChannel(msg.Channel_Id, msg.Planet_Id);

            Member = await msg.GetAuthorAsync();

            Message = msg;
        }
Exemple #5
0
    public async Task Kill(PlanetMessage ctx)
    {
        User user = await ctx.GetAuthorUserAsync();

        if (user.Id != 735182334984219)
        {
            return;
        }
        await ctx.ReplyAsync("Goodbye world...");

        Environment.Exit(666);
    }
Exemple #6
0
        public IEnumerable <PlanetMessage> GetMessages(ulong channel_id)
        {
            ulong channelId = 1;

            PlanetMessage welcome = new PlanetMessage()
            {
                ChannelId = channelId,
                Content   = "Welcome back.",
                TimeSent  = DateTime.UtcNow
            };

            messageCache.Add(welcome);

            return(messageCache.TakeLast(10).ToList());
        }
Exemple #7
0
        public static async Task PostMessage(ulong channelid, ulong planetid, string msg)
        {
            PlanetMessage message = new PlanetMessage()
            {
                Channel_Id = channelid,
                Content    = msg,
                TimeSent   = DateTime.UtcNow,
                Author_Id  = BotId,
                Planet_Id  = planetid
            };

            string json = Newtonsoft.Json.JsonConvert.SerializeObject(message);

            HttpResponseMessage httpresponse = await httpClient.PostAsJsonAsync <PlanetMessage>($"https://valour.gg/Channel/PostMessage?token={Token}", message);
        }
Exemple #8
0
    private static async Task MessageHandler(PlanetMessage ctx)
    {
        var sender = await ctx.GetAuthorUserAsync();

        if (sender.Bot && Self == sender)
        {
            return;
        }

        await using CocaBotContext db = new();
        string id = await ValourToSVID(sender.Id, db);

        if (id is null)
        {
            return;
        }

        HttpClient httpClient = new();
        await httpClient.GetAsync($"https://ubi.vtech.cf/new_valour_message?svid={id}&valour_id={sender.Id}&key={UBIKey}");
    }
Exemple #9
0
    public async Task Confirm(PlanetMessage ctx)
    {
        await using CocaBotContext db = new();
        var sender = await ctx.GetAuthorUserAsync();

        var user = db.Users.Where(x => x.ValourName == sender.Name).SingleOrDefault();

        if (user is null)
        {
            await ctx.ReplyAsync($"Could not find account! Have you done `;valour disconnect {sender.Name}`?");

            return;
        }

        user.Valour     = sender.Id;
        user.ValourName = null;
        await db.SaveChangesAsync();

        await ctx.ReplyAsync("Linked Account!");
    }
Exemple #10
0
        public static async Task PostMessage(ulong channelid, ulong planetid, string msg)
        {
            PlanetMessage message = new PlanetMessage()
            {
                Channel_Id = channelid,
                Content    = msg,
                TimeSent   = DateTime.UtcNow,
                Author_Id  = ulong.Parse(Client.Config.BotId),
                Planet_Id  = planetid
            };

            string json = Newtonsoft.Json.JsonConvert.SerializeObject(message);

            Console.WriteLine("SEND: \n" + json);

            HttpResponseMessage httpresponse = await client.PostAsJsonAsync <PlanetMessage>($"https://valour.gg/Channel/PostMessage?token={Client.Config.AuthKey}", message);

            TaskResult response = Newtonsoft.Json.JsonConvert.DeserializeObject <TaskResult>(await httpresponse.Content.ReadAsStringAsync());

            Console.WriteLine("Sending Message!");

            Console.WriteLine(response.ToString());
        }
Exemple #11
0
 public async Task Uptime(PlanetMessage ctx)
 {
     TimeSpan time = DateTime.Now - Process.GetCurrentProcess().StartTime;
     await ctx.ReplyAsync("Uptime: " + time.Humanize(2));
 }
Exemple #12
0
    public override async Task <bool> ExecuteCheckAsync(PlanetMessage ctx)
    {
        await ctx.ReplyAsync("this is another attribute!");

        return(false);
    }
Exemple #13
0
 public async Task Summon(PlanetMessage ctx)
 => await ctx.ReplyAsync("Hello!");
Exemple #14
0
 public async Task Sheep(PlanetMessage ctx)
 => await ctx.ReplyAsync("beeee!");
Exemple #15
0
 public async Task Website(PlanetMessage ctx)
 => await ctx.ReplyAsync("https://cocabot.cf");
Exemple #16
0
 public async Task Privacy(PlanetMessage ctx)
 => await ctx.ReplyAsync(PrivacyMessage).ConfigureAwait(false);
Exemple #17
0
        static async Task OnMessageRecieve(PlanetMessage message)
        {
            string dictkey = $"{message.Author_Id}-{message.Planet_Id}";

            PlanetMember ClientUser = null;

            ClientUser = await message.GetAuthorAsync();

            if (MessagesThisMinute.ContainsKey(ClientUser.Id))
            {
                MessagesThisMinute[ClientUser.Id] += 1;
            }
            else
            {
                MessagesThisMinute.Add(ClientUser.Id, 1);
            }

            if (message.Author_Id == ulong.Parse(Client.Config.BotId))
            {
                return;
            }

            User user = await Context.Users.FirstOrDefaultAsync(x => x.UserId == message.Author_Id && x.PlanetId == message.Planet_Id);

            if (lotterycache.ContainsKey(message.Planet_Id))
            {
                if (lotterycache[message.Planet_Id].Type == "message")
                {
                    Lottery lottery = await Context.Lotteries.FirstOrDefaultAsync(x => x.PlanetId == message.Planet_Id);

                    lottery.Jackpot += lottery.JackpotIncreasePerMesage;
                    await lottery.AddTickets(message.Author_Id, 1, message.Planet_Id, Context);
                }
            }

            if (message.Content.Substring(0, 1) == Client.Config.CommandSign)
            {
                string command = message.Content.Split(" ")[0];
                command = command.Replace("\n", "");
                List <string> ops = message.Content.Split(" ").ToList();
                command = command.Replace(Client.Config.CommandSign, "");

                if (command == "roll")
                {
                    if (ops.Count < 3)
                    {
                        await PostMessage(message.Channel_Id, message.Planet_Id, "Command Format: /roll <from> <to>");

                        return;
                    }
                    int from = int.Parse(ops[1]);
                    int to   = int.Parse(ops[2]);
                    int num  = rnd.Next(from, to);
                    await PostMessage(message.Channel_Id, message.Planet_Id, $"Roll: {num}");
                }
                if (command == "eco")
                {
                    if (ops.Count == 1)
                    {
                        ops.Add("");
                    }
                    switch (ops[1])
                    {
                    case "cap":
                        int total = 0;
                        foreach (User USER in Context.Users)
                        {
                            total += (int)USER.Coins;
                        }
                        await PostMessage(message.Channel_Id, message.Planet_Id, $"Eco cap: {total} coins");

                        break;

                    default:
                        await PostMessage(message.Channel_Id, message.Planet_Id, "Available Commands: /eco cap");

                        break;
                    }
                }

                if (command == "forcerolepayout")
                {
                    if (await ClientUser.IsOwner() != true)
                    {
                        await PostMessage(message.Channel_Id, message.Planet_Id, $"Only the owner of this server can use this command!");

                        return;
                    }
                    await Context.UpdateRoleIncomes(planets, true, Context);

                    await PostMessage(message.Channel_Id, message.Planet_Id, "Successfully forced a role payout.");
                }
                if (command == "lottery")
                {
                    if (ops.Count() == 1)
                    {
                        ops.Add("");
                    }
                    switch (ops[1])
                    {
                    case "timeleft":
                        Lottery lottery = await Context.Lotteries.FirstOrDefaultAsync(x => x.PlanetId == message.Planet_Id);

                        if (lottery == null)
                        {
                            await PostMessage(message.Channel_Id, message.Planet_Id, $"There is no lottery currently going on!");

                            break;
                        }
                        TimeSpan timeleft = lottery.EndDate.Subtract(DateTime.UtcNow);
                        await PostMessage(message.Channel_Id, message.Planet_Id, $"{timeleft.Hours} hours left");

                        break;

                    case "tickets":
                        LotteryTicket ticket = await Context.LotteryTickets.FirstOrDefaultAsync(x => x.PlanetId == message.Planet_Id && x.UserId == message.Author_Id);

                        if (ticket == null)
                        {
                            await PostMessage(message.Channel_Id, message.Planet_Id, $"There is no lottery currently going on!");

                            break;
                        }
                        await PostMessage(message.Channel_Id, message.Planet_Id, $"You have {ticket.Tickets} tickets");

                        break;

                    case "jackpot":
                        lottery = await Context.Lotteries.FirstOrDefaultAsync(x => x.PlanetId == message.Planet_Id);

                        if (lottery == null)
                        {
                            await PostMessage(message.Channel_Id, message.Planet_Id, $"There is no lottery currently going on!");

                            break;
                        }
                        await PostMessage(message.Channel_Id, message.Planet_Id, $"The current jackpot is {lottery.Jackpot}");

                        break;

                    case "create":

                        if (await ClientUser.IsOwner() != true)
                        {
                            await PostMessage(message.Channel_Id, message.Planet_Id, $"Only the owner of this server can use this command!");

                            break;
                        }

                        if (ops.Count() < 4)
                        {
                            await PostMessage(message.Channel_Id, message.Planet_Id, "Command Format: /lottery create coin <hours> or /lottery create message <how many coins will each message add> <hours>");

                            break;
                        }

                        string type = ops[2];

                        int HoursToLast = 0;

                        if (type == "message")
                        {
                            if (ops.Count() < 5)
                            {
                                await PostMessage(message.Channel_Id, message.Planet_Id, "Command Format: /lottery create message <how many coins will each message add> <hours>");

                                break;
                            }
                            HoursToLast = int.Parse(ops[4]);
                        }
                        else
                        {
                            HoursToLast = int.Parse(ops[3]);
                        }

                        if (HoursToLast > 24)
                        {
                            await PostMessage(message.Channel_Id, message.Planet_Id, "You can not have a lottery last more than 24 hours!");

                            break;
                        }

                        if (type != "coin" && type != "message")
                        {
                            await PostMessage(message.Channel_Id, message.Planet_Id, "Type must either by coin or message!");

                            break;
                        }

                        // check if the planet is areadly doing a lottery

                        lottery = await Context.Lotteries.FirstOrDefaultAsync(x => x.PlanetId == message.Planet_Id);

                        if (lottery != null)
                        {
                            await PostMessage(message.Channel_Id, message.Planet_Id, "You can not have two lotteries running at the same time!");

                            break;
                        }

                        lottery = new Lottery();

                        lottery.StartDate = DateTime.UtcNow;
                        lottery.Type      = type;
                        lottery.PlanetId  = message.Planet_Id;
                        lottery.EndDate   = DateTime.UtcNow.AddHours(HoursToLast);
                        lottery.Jackpot   = 0;
                        lottery.ChannelId = message.Channel_Id;

                        if (type == "message")
                        {
                            lottery.JackpotIncreasePerMesage = (double)int.Parse(ops[3]);
                        }
                        else
                        {
                            lottery.JackpotIncreasePerMesage = 0;
                        }
                        await Context.Lotteries.AddAsync(lottery);

                        lotterycache.Add(lottery.PlanetId, lottery);
                        await PostMessage(message.Channel_Id, message.Planet_Id, "Successfully created a lottery.");

                        await Context.SaveChangesAsync();

                        break;

                    default:
                        await PostMessage(message.Channel_Id, message.Planet_Id, "Command Format: /lottery create coin <hours> or /lottery create message <how many coins will each message add> <hours>");

                        break;
                    }
                }
            }

            Console.WriteLine(message.Content);
        }
Exemple #18
0
 /// <summary>
 /// Returns true if the client message matches this server message
 /// </summary>
 public bool EqualsMessage(PlanetMessage message)
 {
     return(Hash == message.GetHash());
 }
Exemple #19
0
 public static void AddToQueue(PlanetMessage message)
 {
     MessageQueue.Add(message);
 }
 /// <summary>
 /// Returns client version using shared implementation
 /// </summary>
 public static ClientPlanetMessage FromBase(PlanetMessage message, IMapper mapper)
 {
     return(mapper.Map <ClientPlanetMessage>(message));
 }
Exemple #21
0
 public async Task Code(PlanetMessage ctx)
 => await ctx.ReplyAsync(CodeMessage).ConfigureAwait(false);