Skip to content

Commit

Permalink
added files
Browse files Browse the repository at this point in the history
  • Loading branch information
PizzaConsole committed Feb 9, 2021
1 parent 654d92e commit 5d9fa5a
Show file tree
Hide file tree
Showing 10 changed files with 482 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

config.json

# User-specific files
*.rsuser
*.suo
Expand Down Expand Up @@ -347,4 +349,4 @@ healthchecksdb
MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
.ionide/
67 changes: 67 additions & 0 deletions Commands/BasicCommandsModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.Interactivity;
using System;
using System.Threading.Tasks;

namespace PoisnCopy.Commands
{
public class BasicCommandsModule : IModule
{
/* Commands in DSharpPlus.CommandsNext are identified by supplying a Command attribute to a method in any class you've loaded into it. */
/* The description is just a string supplied when you use the help command included in CommandsNext. */

[Command("connections")]
[Description("Simple command to see how many servers the bot is on.")]
public async Task Connections(CommandContext ctx)
{
await ctx.TriggerTypingAsync();

var connections = ctx.Client.Guilds;
await ctx.RespondAsync($"I am running on {connections} servers");
}

[Command("alive")]
[Description("Simple command to test if the bot is running!")]
public async Task Alive(CommandContext ctx)
{
/* Trigger the Typing... in discord */
await ctx.TriggerTypingAsync();

/* Send the message "I'm Alive!" to the channel the message was recieved from */
await ctx.RespondAsync("I'm alive!");
}

[Command("interact")]
[Description("Simple command to test interaction!")]
public async Task Interact(CommandContext ctx)
{
/* Trigger the Typing... in discord */
await ctx.TriggerTypingAsync();

/* Send the message "I'm Alive!" to the channel the message was recieved from */
await ctx.RespondAsync("How are you today?");

var intr = ctx.Client.GetInteractivityModule(); // Grab the interactivity module
var reminderContent = await intr.WaitForMessageAsync(
c => c.Author.Id == ctx.Message.Author.Id, // Make sure the response is from the same person who sent the command
TimeSpan.FromSeconds(60) // Wait 60 seconds for a response instead of the default 30 we set earlier!
);

// You can also check for a specific message by doing something like
// c => c.Content == "something"

// Null if the user didn't respond before the timeout
if (reminderContent == null)
{
await ctx.RespondAsync("Sorry, I didn't get a response!");
return;
}

// Homework: have this change depending on if they say "good" or "bad", etc.
await ctx.RespondAsync("Sucks to suck");
}
}
}
141 changes: 141 additions & 0 deletions Commands/CopyChannelCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.Interactivity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using static DSharpPlus.Entities.DiscordEmbedBuilder;

namespace PoisnCopy.Commands
{
[RequirePermissions(Permissions.Administrator)]
[Hidden]
public class CopyChannelCommand : IModule
{
[Command("copychannel")]
[Description("Copy a channel")]
public async Task CopyChannel(CommandContext ctx)
{
await ctx.TriggerTypingAsync();

await ctx.RespondAsync("Which Channel would you like to copy? (copy and paste the Id) Pleaes wait while I find all of your channels, I will give you a message when I have found them all.");

await ctx.TriggerTypingAsync();
var textChannels = ctx.Guild.Channels.Where(i => i.Type == ChannelType.Text).ToList();
foreach (var txtChan in textChannels)
{
await ctx.TriggerTypingAsync();
await ctx.RespondAsync($"`{txtChan.Id}-{txtChan.Name}`");
await ctx.TriggerTypingAsync();
}
await ctx.RespondAsync($"Thats all of the channels!");

var intr = ctx.Client.GetInteractivityModule(); // Grab the interactivity module
var response = await intr.WaitForMessageAsync(
c => c.Author.Id == ctx.Message.Author.Id, // Make sure the response is from the same person who sent the command
TimeSpan.FromSeconds(60) // Wait 60 seconds for a response instead of the default 30 we set earlier!
);

if (response == null)
{
await ctx.RespondAsync("Sorry, I didn't get a response!");
return;
}

var selectedChannel = textChannels.FirstOrDefault(i => i.Id.ToString() == response.Message.Content);

if (selectedChannel == null)
{
await ctx.RespondAsync("Sorry, but that channel does not exist!");
return;
}

await ctx.RespondAsync($"Copy command: `pc.loadchannel {selectedChannel.GuildId} {selectedChannel.Id}`");
}

[Command("loadchannel")]
[Description("Load a copied channel")]
public async Task LoadChannel(CommandContext ctx, ulong guildId, ulong channelId)
{
var guild = await ctx.Client.GetGuildAsync(guildId);
var selectedChannel = guild.GetChannel(channelId);

await ctx.RespondAsync("What do you want the new channel to be named?");

var intr = ctx.Client.GetInteractivityModule(); // Grab the interactivity module
var response = await intr.WaitForMessageAsync(
c => c.Author.Id == ctx.Message.Author.Id, // Make sure the response is from the same person who sent the command
TimeSpan.FromSeconds(60) // Wait 60 seconds for a response instead of the default 30 we set earlier!
);

if (response == null)
{
await ctx.RespondAsync("Sorry, I didn't get a response!");
return;
}

if (string.IsNullOrEmpty(response.Message.Content))
{
await ctx.RespondAsync("Name cannot be empty!");
return;
}

var channelName = response.Message.Content;

await ctx.RespondAsync("Starting copy...");

await ctx.RespondAsync("Collecting messages...");

var messag = await selectedChannel.GetMessagesAsync();

var messCopy = messag.ToList();

var more = await selectedChannel.GetMessagesAsync(100, messag.LastOrDefault().Id);

while (more.Count > 0)
{
messCopy.AddRange(more);
more = await selectedChannel.GetMessagesAsync(100, more.LastOrDefault().Id);
}

await ctx.RespondAsync("Organizing messages...");

messCopy.Reverse();

var newMess = new List<DiscordMessage>();

await ctx.RespondAsync("Creating channel...");

var newChan = await ctx.Guild.CreateChannelAsync(channelName, selectedChannel.Type);

await ctx.RespondAsync($"Posting {messCopy.Count} messages... (this could take awhile)");

foreach (var mes in messCopy)
{
if (!string.IsNullOrEmpty(mes.Content))
{
var whAu = new EmbedAuthor { Name = mes.Author.Username, IconUrl = mes.Author.AvatarUrl };
var what = new DiscordEmbedBuilder { Description = mes.Content, Author = whAu, Timestamp = mes.Timestamp };

await newChan.SendMessageAsync(null, false, what);
}

if (mes.Attachments.Count > 0)
{
foreach (var att in mes.Attachments)
{
var whAu = new EmbedAuthor { Name = mes.Author.Username, IconUrl = mes.Author.AvatarUrl };
var what = new DiscordEmbedBuilder { ImageUrl = att.Url, Author = whAu, Timestamp = mes.Timestamp };

await newChan.SendMessageAsync(null, false, what);
}
}
}

await ctx.RespondAsync($"{newChan.Name} copy complete!");
}
}
}
10 changes: 10 additions & 0 deletions IModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace PoisnCopy
{
public interface IModule
{
}
}
20 changes: 20 additions & 0 deletions PoisnCopy.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DSharpPlus" Version="3.2.3" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="3.2.3" />
<PackageReference Include="DSharpPlus.Interactivity" Version="3.2.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.9" />
</ItemGroup>

<ItemGroup>
<None Update="config.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions PoisnCopy.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30611.23
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoisnCopy", "PoisnCopy.csproj", "{071E04E6-CEDB-414B-BABA-E2AEAF939586}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{071E04E6-CEDB-414B-BABA-E2AEAF939586}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{071E04E6-CEDB-414B-BABA-E2AEAF939586}.Debug|Any CPU.Build.0 = Debug|Any CPU
{071E04E6-CEDB-414B-BABA-E2AEAF939586}.Release|Any CPU.ActiveCfg = Release|Any CPU
{071E04E6-CEDB-414B-BABA-E2AEAF939586}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {05007DA9-D6E7-4D2A-BB80-EBF775A7292D}
EndGlobalSection
EndGlobal
Loading

0 comments on commit 5d9fa5a

Please sign in to comment.