Compare commits
1 commit
master
...
unit-testi
Author | SHA1 | Date | |
---|---|---|---|
476ed37d20 |
324 changed files with 1043 additions and 24978 deletions
38
.deploy.yml
38
.deploy.yml
|
@ -1,38 +0,0 @@
|
|||
---
|
||||
- name: Geekbot Deploy
|
||||
hosts: all
|
||||
remote_user: geekbot
|
||||
vars:
|
||||
ansible_port: 65432
|
||||
ansible_python_interpreter: /usr/bin/python3
|
||||
tasks:
|
||||
- name: Login to Gitlab Docker Registry
|
||||
'community.docker.docker_login':
|
||||
registry_url: "{{ lookup('env', 'CI_REGISTRY') }}"
|
||||
username: "{{ lookup('env', 'CI_REGISTRY_USER') }}"
|
||||
password: "{{ lookup('env', 'CI_REGISTRY_PASSWORD') }}"
|
||||
reauthorize: yes
|
||||
- name: Replace Prod Container
|
||||
'community.docker.docker_container':
|
||||
name: GeekbotProd
|
||||
image: "{{ lookup('env', 'IMAGE_TAG') }}"
|
||||
recreate: yes
|
||||
pull: yes
|
||||
restart_policy: always
|
||||
keep_volumes: no
|
||||
ports:
|
||||
- "12995:12995"
|
||||
env:
|
||||
GEEKBOT_DB_HOST: "{{ lookup('env', 'GEEKBOT_DB_HOST') }}"
|
||||
GEEKBOT_DB_USER: "{{ lookup('env', 'GEEKBOT_DB_USER') }}"
|
||||
GEEKBOT_DB_PASSWORD: "{{ lookup('env', 'GEEKBOT_DB_PASSWORD') }}"
|
||||
GEEKBOT_DB_PORT: "{{ lookup('env', 'GEEKBOT_DB_PORT') }}"
|
||||
GEEKBOT_DB_DATABASE: "{{ lookup('env', 'GEEKBOT_DB_DATABASE') }}"
|
||||
GEEKBOT_DB_REQUIRE_SSL: "true"
|
||||
GEEKBOT_DB_TRUST_CERT: "true"
|
||||
GEEKBOT_SUMOLOGIC: "{{ lookup('env', 'GEEKBOT_SUMOLOCIG') }}"
|
||||
GEEKBOT_SENTRY: "{{ lookup('env', 'GEEKBOT_SENTRY') }}"
|
||||
GEEKBOT_DB_REDSHIFT_COMPAT: "true"
|
||||
- name: Cleanup Old Container
|
||||
'community.docker.docker_prune':
|
||||
images: yes
|
14
.gitignore
vendored
14
.gitignore
vendored
|
@ -1,10 +1,8 @@
|
|||
/*/**/bin
|
||||
/*/**/obj
|
||||
src/Bot/tmp/
|
||||
src/Bot/Logs/*
|
||||
!/src/Bot/Logs/.keep
|
||||
Geekbot.net/bin
|
||||
Geekbot.net/obj
|
||||
Tests/bin
|
||||
Tests/obj
|
||||
Backup/
|
||||
.vs/
|
||||
UpgradeLog.htm
|
||||
.idea
|
||||
.vscode
|
||||
Geekbot.net.sln.DotSettings.user
|
||||
app
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
stages:
|
||||
- build
|
||||
- docker
|
||||
- deploy
|
||||
- ops
|
||||
|
||||
variables:
|
||||
VERSION: 4.4.0-V$CI_COMMIT_SHORT_SHA
|
||||
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
|
||||
|
||||
Build:
|
||||
stage: build
|
||||
image: mcr.microsoft.com/dotnet/sdk:6.0
|
||||
artifacts:
|
||||
expire_in: 1h
|
||||
paths:
|
||||
- app
|
||||
script:
|
||||
- dotnet restore
|
||||
- dotnet test tests
|
||||
- dotnet publish --version-suffix "$VERSION" -r linux-x64 -c Release -p:DebugType=embedded --no-self-contained -o ./app ./src/Startup/
|
||||
|
||||
Package:
|
||||
stage: docker
|
||||
image: docker
|
||||
only:
|
||||
- master
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
|
||||
- docker build -t $IMAGE_TAG .
|
||||
- docker push $IMAGE_TAG
|
||||
|
||||
Deploy:
|
||||
stage: deploy
|
||||
image: quay.io/ansible/ansible-runner:stable-2.12-latest
|
||||
only:
|
||||
- master
|
||||
variables:
|
||||
ANSIBLE_NOCOWS: 1
|
||||
before_script:
|
||||
- mkdir /root/.ssh
|
||||
- cp $SSH_PRIVATE_KEY /root/.ssh/id_ed25519
|
||||
- cp $SSH_PUBLIC_KEY /root/.ssh/id_ed25519.pub
|
||||
- chmod -R 600 /root/.ssh
|
||||
- ssh-keyscan -p 65432 $PROD_IP > /root/.ssh/known_hosts
|
||||
script:
|
||||
- ansible-galaxy collection install -r ansible-requirements.yml
|
||||
- ansible-playbook -i $PROD_IP, .deploy.yml
|
||||
|
||||
Sentry:
|
||||
stage: ops
|
||||
image: getsentry/sentry-cli
|
||||
allow_failure: true
|
||||
only:
|
||||
- master
|
||||
script:
|
||||
- sentry-cli releases new -p geekbot $VERSION
|
||||
- sentry-cli releases set-commits --auto $VERSION
|
||||
- sentry-cli releases deploys $VERSION new -e Production
|
||||
|
||||
Github Mirror:
|
||||
stage: ops
|
||||
image: runebaas/rsync-ssh-git
|
||||
only:
|
||||
- master
|
||||
script:
|
||||
- git push https://runebaas:$TOKEN@github.com/pizzaandcoffee/Geekbot.net.git origin/master:master -f
|
52
.vscode/launch.json
vendored
Normal file
52
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"stopAtEntry": false,
|
||||
"console": "internalConsole"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Launch (web)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"stopAtEntry": false,
|
||||
"launchBrowser": {
|
||||
"enabled": true,
|
||||
"args": "${auto-detect-url}",
|
||||
"windows": {
|
||||
"command": "cmd.exe",
|
||||
"args": "/C start ${auto-detect-url}"
|
||||
},
|
||||
"osx": {
|
||||
"command": "open"
|
||||
},
|
||||
"linux": {
|
||||
"command": "xdg-open"
|
||||
}
|
||||
},
|
||||
"env": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"sourceFileMap": {
|
||||
"/Views": "${workspaceRoot}/Views"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command:pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
FROM mcr.microsoft.com/dotnet/aspnet:6.0
|
||||
|
||||
COPY ./app /app/
|
||||
|
||||
EXPOSE 12995/tcp
|
||||
WORKDIR /app
|
||||
ENTRYPOINT ./Geekbot
|
|
@ -3,19 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.0.0
|
||||
MinimumVisualStudioVersion = 10.0.0.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "tests\Tests.csproj", "{4CAF5F02-EFFE-4FDA-BD44-EEADDBA9600E}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Geekbot.net", "Geekbot.net/Geekbot.net.csproj", "{FDCB3D92-E7B5-47BB-A9B5-CFAEFA57CDB4}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "src\Core\Core.csproj", "{47671723-52A9-4668-BBC5-2BA76AE3B288}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web", "src\Web\Web.csproj", "{0A63D5DC-6325-4F53-8ED2-9843239B76CC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bot", "src\Bot\Bot.csproj", "{DBF79896-9F7F-443D-B336-155E276DFF16}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands", "src\Commands\Commands.csproj", "{7C771DFE-912A-4276-B0A6-047E09603F1E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interactions", "src\Interactions\Interactions.csproj", "{FF6859D9-C539-4910-BE1E-9ECFED2F46FA}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Startup", "src\Startup\Startup.csproj", "{A691B018-4B19-4A7A-A0F6-DBB17641254F}"
|
||||
Project("{64BFF91A-5FCE-45C2-B281-5EA31729FFBF}") = "Tests", "Tests\Tests.csproj", "{CE7B71E3-F73A-40D1-901C-C20BEFB15851}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -23,34 +13,14 @@ Global
|
|||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{4CAF5F02-EFFE-4FDA-BD44-EEADDBA9600E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4CAF5F02-EFFE-4FDA-BD44-EEADDBA9600E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4CAF5F02-EFFE-4FDA-BD44-EEADDBA9600E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4CAF5F02-EFFE-4FDA-BD44-EEADDBA9600E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{47671723-52A9-4668-BBC5-2BA76AE3B288}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{47671723-52A9-4668-BBC5-2BA76AE3B288}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{47671723-52A9-4668-BBC5-2BA76AE3B288}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{47671723-52A9-4668-BBC5-2BA76AE3B288}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0A63D5DC-6325-4F53-8ED2-9843239B76CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0A63D5DC-6325-4F53-8ED2-9843239B76CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0A63D5DC-6325-4F53-8ED2-9843239B76CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0A63D5DC-6325-4F53-8ED2-9843239B76CC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DBF79896-9F7F-443D-B336-155E276DFF16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DBF79896-9F7F-443D-B336-155E276DFF16}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DBF79896-9F7F-443D-B336-155E276DFF16}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DBF79896-9F7F-443D-B336-155E276DFF16}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7C771DFE-912A-4276-B0A6-047E09603F1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7C771DFE-912A-4276-B0A6-047E09603F1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7C771DFE-912A-4276-B0A6-047E09603F1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7C771DFE-912A-4276-B0A6-047E09603F1E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FF6859D9-C539-4910-BE1E-9ECFED2F46FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FF6859D9-C539-4910-BE1E-9ECFED2F46FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FF6859D9-C539-4910-BE1E-9ECFED2F46FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FF6859D9-C539-4910-BE1E-9ECFED2F46FA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A691B018-4B19-4A7A-A0F6-DBB17641254F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A691B018-4B19-4A7A-A0F6-DBB17641254F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A691B018-4B19-4A7A-A0F6-DBB17641254F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A691B018-4B19-4A7A-A0F6-DBB17641254F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FDCB3D92-E7B5-47BB-A9B5-CFAEFA57CDB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FDCB3D92-E7B5-47BB-A9B5-CFAEFA57CDB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FDCB3D92-E7B5-47BB-A9B5-CFAEFA57CDB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FDCB3D92-E7B5-47BB-A9B5-CFAEFA57CDB4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CE7B71E3-F73A-40D1-901C-C20BEFB15851}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CE7B71E3-F73A-40D1-901C-C20BEFB15851}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CE7B71E3-F73A-40D1-901C-C20BEFB15851}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CE7B71E3-F73A-40D1-901C-C20BEFB15851}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSORHOLDER_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
|
||||
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIMIT/@EntryValue">200</s:Int64>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
28
Geekbot.net.userprefs
Normal file
28
Geekbot.net.userprefs
Normal file
|
@ -0,0 +1,28 @@
|
|||
<Properties StartupConfiguration="{FDCB3D92-E7B5-47BB-A9B5-CFAEFA57CDB4}|Default">
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Tests/UnitTest1.cs">
|
||||
<Files>
|
||||
<File FileName="Tests/UnitTest1.cs" Line="1" Column="1" />
|
||||
</Files>
|
||||
<Pads>
|
||||
<Pad Id="MonoDevelop.UnitTesting.TestPad">
|
||||
<State name="__root__">
|
||||
<Node name="Geekbot.net" expanded="True">
|
||||
<Node name="Tests" expanded="True">
|
||||
<Node name="Tests" expanded="True">
|
||||
<Node name="UnitTest1" selected="True" />
|
||||
</Node>
|
||||
</Node>
|
||||
</Node>
|
||||
</State>
|
||||
</Pad>
|
||||
</Pads>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<BreakpointStore>
|
||||
<Breakpoint file="/Users/dboerlage/dev/priv/Geekbot.net/Tests/UnitTest1.cs" relfile="Tests/UnitTest1.cs" line="27" column="1" />
|
||||
</BreakpointStore>
|
||||
</MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
|
||||
<MultiItemStartupConfigurations />
|
||||
</Properties>
|
33
Geekbot.net/Geekbot.net.csproj
Executable file
33
Geekbot.net/Geekbot.net.csproj
Executable file
|
@ -0,0 +1,33 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Cleverbot" Version="0.9.0" />
|
||||
<PackageReference Include="Discord.Net">
|
||||
<Version>1.0.0-rc</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Google.Apis.YouTube.v3">
|
||||
<Version>1.25.0.760</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="HtmlAgilityPack.NetCore">
|
||||
<Version>1.5.0.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="RestSharp.NetCore">
|
||||
<Version>105.2.4-rc4-24214-01</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="StackExchange.Redis">
|
||||
<Version>1.2.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Net.Http">
|
||||
<Version>4.3.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Runtime.Serialization.Json">
|
||||
<Version>4.3.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Runtime.Serialization.Primitives">
|
||||
<Version>4.3.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
19
Geekbot.net/Lib/IClients/CatClient.cs
Normal file
19
Geekbot.net/Lib/IClients/CatClient.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using RestSharp;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public interface ICatClient
|
||||
{
|
||||
IRestClient Client { get; set; }
|
||||
}
|
||||
|
||||
public class CatClient : ICatClient
|
||||
{
|
||||
public CatClient()
|
||||
{
|
||||
Client = new RestClient("http://random.cat");
|
||||
}
|
||||
|
||||
public IRestClient Client { get; set; }
|
||||
}
|
||||
}
|
29
Geekbot.net/Lib/IClients/RandomClient.cs
Normal file
29
Geekbot.net/Lib/IClients/RandomClient.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
|
||||
namespace Geekbot.net.Lib.IClients
|
||||
{
|
||||
|
||||
public interface IRandomClient
|
||||
{
|
||||
Random Client { get; set; }
|
||||
}
|
||||
|
||||
public sealed class RandomClient : IRandomClient
|
||||
{
|
||||
public RandomClient()
|
||||
{
|
||||
try
|
||||
{
|
||||
Client = new Random();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Console.WriteLine("Start Redis pls...");
|
||||
Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public Random Client { get; set; }
|
||||
}
|
||||
|
||||
}
|
30
Geekbot.net/Lib/IClients/RedisClient.cs
Normal file
30
Geekbot.net/Lib/IClients/RedisClient.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using System;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Geekbot.net.Lib
|
||||
{
|
||||
public interface IRedisClient
|
||||
{
|
||||
IDatabase Client { get; set; }
|
||||
}
|
||||
|
||||
public sealed class RedisClient : IRedisClient
|
||||
{
|
||||
public RedisClient()
|
||||
{
|
||||
try
|
||||
{
|
||||
var redis = ConnectionMultiplexer.Connect("127.0.0.1:6379");
|
||||
Client = redis.GetDatabase(6);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Console.WriteLine("Start Redis pls...");
|
||||
Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public IDatabase Client { get; set; }
|
||||
}
|
||||
}
|
||||
|
33
Geekbot.net/Lib/LevelCalc.cs
Normal file
33
Geekbot.net/Lib/LevelCalc.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Geekbot.net.Lib
|
||||
{
|
||||
public class LevelCalc
|
||||
{
|
||||
private static int GetExperienceAtLevel(int level)
|
||||
{
|
||||
double total = 0;
|
||||
for (int i = 1; i < level; i++)
|
||||
{
|
||||
total += Math.Floor(i + 300 * Math.Pow(2, i / 7.0));
|
||||
}
|
||||
|
||||
return (int)Math.Floor(total / 16);
|
||||
}
|
||||
|
||||
public static int GetLevelAtExperience(int experience)
|
||||
{
|
||||
int index;
|
||||
|
||||
for (index = 0; index < 120; index++)
|
||||
{
|
||||
if (GetExperienceAtLevel(index + 1) > experience)
|
||||
break;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
}
|
||||
}
|
34
Geekbot.net/Lib/StatsRecorder.cs
Normal file
34
Geekbot.net/Lib/StatsRecorder.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.WebSocket;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Geekbot.net.Lib
|
||||
{
|
||||
public class StatsRecorder
|
||||
{
|
||||
|
||||
private readonly SocketMessage message;
|
||||
private readonly IDatabase redis;
|
||||
|
||||
public StatsRecorder(SocketMessage message, IRedisClient redisClient)
|
||||
{
|
||||
this.message = message;
|
||||
redis = redisClient.Client;
|
||||
}
|
||||
|
||||
public async Task UpdateUserRecordAsync()
|
||||
{
|
||||
var guildId = ((SocketGuildChannel) message.Channel).Guild.Id;
|
||||
var key = guildId + "-" + message.Author.Id + "-messages";
|
||||
await redis.StringIncrementAsync(key);
|
||||
}
|
||||
|
||||
public async Task UpdateGuildRecordAsync()
|
||||
{
|
||||
var guildId = ((SocketGuildChannel) message.Channel).Guild.Id;
|
||||
var key = guildId + "-messages";
|
||||
await redis.StringIncrementAsync(key);
|
||||
}
|
||||
}
|
||||
}
|
41
Geekbot.net/Modules/AdminCmd.cs
Normal file
41
Geekbot.net/Modules/AdminCmd.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
[Group("admin")]
|
||||
public class AdminCmd : ModuleBase
|
||||
{
|
||||
private readonly IRedisClient redis;
|
||||
public AdminCmd(IRedisClient redisClient)
|
||||
{
|
||||
redis = redisClient;
|
||||
}
|
||||
|
||||
[RequireUserPermission(Discord.GuildPermission.Administrator)]
|
||||
[Command("welcome", RunMode = RunMode.Async), Summary("Set a Welcome Message (use '$user' to mention the new joined user).")]
|
||||
public async Task SetWelcomeMessage([Remainder, Summary("The message")] string welcomeMessage)
|
||||
{
|
||||
var key = Context.Guild.Id + "-welcomeMsg";
|
||||
redis.Client.StringSet(key, welcomeMessage);
|
||||
var formatedMessage = welcomeMessage.Replace("$user", Context.User.Mention);
|
||||
await ReplyAsync("Welcome message has been changed\r\nHere is an example of how it would look:\r\n" +
|
||||
formatedMessage);
|
||||
}
|
||||
|
||||
[Command("youtubekey", RunMode = RunMode.Async), Summary("Set the youtube api key")]
|
||||
public async Task SetYoutubeKey([Summary("API Key")] string key)
|
||||
{
|
||||
var botOwner = redis.Client.StringGet("botOwner");
|
||||
if (!Context.User.Id.ToString().Equals(botOwner.ToString()))
|
||||
{
|
||||
await ReplyAsync($"Sorry, only the botowner can do this ({botOwner}");
|
||||
return;
|
||||
}
|
||||
|
||||
redis.Client.StringSet("youtubeKey", key);
|
||||
await ReplyAsync("Apikey has been set");
|
||||
}
|
||||
}
|
||||
}
|
51
Geekbot.net/Modules/Cat.cs
Normal file
51
Geekbot.net/Modules/Cat.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using RestSharp;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class Cat : ModuleBase, AsyncReplier
|
||||
{
|
||||
private readonly ICatClient catClient;
|
||||
private readonly AsyncReplier _asyncReplier;
|
||||
private readonly Func<IRestRequest> _requestFunc;
|
||||
|
||||
public class CatResponse
|
||||
{
|
||||
public string file { get; set; }
|
||||
}
|
||||
|
||||
public Cat(ICatClient catClient)
|
||||
{
|
||||
this.catClient = catClient;
|
||||
_asyncReplier = this;
|
||||
_requestFunc = (() => new RestRequest("meow.php", Method.GET));
|
||||
}
|
||||
//
|
||||
// public Cat(ICatClient catClient, Func<IRestRequest> requestFunc, AsyncReplier asyncReplier)
|
||||
// {
|
||||
// this.catClient = catClient;
|
||||
// _asyncReplier = asyncReplier ?? this;
|
||||
// _requestFunc = requestFunc ?? (() => new RestRequest("meow.php", Method.GET));
|
||||
// }
|
||||
|
||||
[Command("cat", RunMode = RunMode.Async), Summary("Return a random image of a cat.")]
|
||||
public async Task Say()
|
||||
{
|
||||
var request = _requestFunc();
|
||||
var response = catClient.Client.Execute<CatResponse>(request);
|
||||
await _asyncReplier.ReplyAsyncInt(response.Data.file);
|
||||
}
|
||||
|
||||
public async Task ReplyAsyncInt(dynamic data)
|
||||
{
|
||||
await ReplyAsync(data);
|
||||
}
|
||||
}
|
||||
|
||||
public interface AsyncReplier
|
||||
{
|
||||
Task ReplyAsyncInt(dynamic data);
|
||||
}
|
||||
}
|
93
Geekbot.net/Modules/Counters.cs
Normal file
93
Geekbot.net/Modules/Counters.cs
Normal file
|
@ -0,0 +1,93 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class Counters : ModuleBase
|
||||
{
|
||||
private readonly IRedisClient redis;
|
||||
public Counters(IRedisClient redisClient)
|
||||
{
|
||||
redis = redisClient;
|
||||
}
|
||||
|
||||
[Command("good", RunMode = RunMode.Async), Summary("Increase Someones Karma")]
|
||||
public async Task Good([Summary("The someone")] IUser user)
|
||||
{
|
||||
var lastKarma = GetLastKarma();
|
||||
if (user.Id == Context.User.Id)
|
||||
{
|
||||
await ReplyAsync($"Sorry {Context.User.Username}, but you can't give yourself karma");
|
||||
}
|
||||
else if (lastKarma > GetUnixTimestamp())
|
||||
{
|
||||
await ReplyAsync($"Sorry {Context.User.Username}, but you have to wait {GetTimeLeft(lastKarma)} before you can give karma again...");
|
||||
}
|
||||
else
|
||||
{
|
||||
var key = Context.Guild.Id + "-" + user.Id + "-karma";
|
||||
var badJokes = (int)redis.Client.StringGet(key);
|
||||
redis.Client.StringSet(key, (badJokes + 1).ToString());
|
||||
var lastKey = Context.Guild.Id + "-" + Context.User.Id + "-karma-timeout";
|
||||
redis.Client.StringSet(lastKey, GetNewLastKarma());
|
||||
await ReplyAsync($"{Context.User.Username} gave {user.Mention} karma");
|
||||
}
|
||||
}
|
||||
|
||||
[Command("bad", RunMode = RunMode.Async), Summary("Decrease Someones Karma")]
|
||||
public async Task Bad([Summary("The someone")] IUser user)
|
||||
{
|
||||
var lastKarma = GetLastKarma();
|
||||
if (user.Id == Context.User.Id)
|
||||
{
|
||||
await ReplyAsync($"Sorry {Context.User.Username}, but you can't lower your own karma");
|
||||
}
|
||||
else if (lastKarma > GetUnixTimestamp())
|
||||
{
|
||||
await ReplyAsync($"Sorry {Context.User.Username}, but you have to wait {GetTimeLeft(lastKarma)} before you can take karma again...");
|
||||
}
|
||||
else
|
||||
{
|
||||
var key = Context.Guild.Id + "-" + user.Id + "-karma";
|
||||
var badJokes = (int)redis.Client.StringGet(key);
|
||||
redis.Client.StringSet(key, (badJokes - 1).ToString());
|
||||
var lastKey = Context.Guild.Id + "-" + Context.User.Id + "-karma-timeout";
|
||||
redis.Client.StringSet(lastKey, GetNewLastKarma());
|
||||
await ReplyAsync($"{Context.User.Username} lowered {user.Mention}'s karma");
|
||||
}
|
||||
}
|
||||
|
||||
private int GetLastKarma()
|
||||
{
|
||||
var lastKey = Context.Guild.Id + "-" + Context.User.Id + "-karma-timeout";
|
||||
var redisReturn = redis.Client.StringGet(lastKey);
|
||||
if (!int.TryParse(redisReturn.ToString(), out var i))
|
||||
{
|
||||
i = GetUnixTimestamp();
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
private int GetNewLastKarma()
|
||||
{
|
||||
var timeout = TimeSpan.FromMinutes(3);
|
||||
return (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).Add(timeout)).TotalSeconds;
|
||||
}
|
||||
|
||||
private int GetUnixTimestamp()
|
||||
{
|
||||
return (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||
}
|
||||
|
||||
private string GetTimeLeft(int time)
|
||||
{
|
||||
DateTime dtDateTime = new DateTime(1970,1,1,0,0,0,0,DateTimeKind.Utc);
|
||||
dtDateTime = dtDateTime.AddSeconds( time ).ToLocalTime();
|
||||
var dt = dtDateTime.Subtract(DateTime.Now);
|
||||
return $"{dt.Minutes} Minutes and {dt.Seconds} Seconds";
|
||||
}
|
||||
}
|
||||
}
|
45
Geekbot.net/Modules/EightBall.cs
Normal file
45
Geekbot.net/Modules/EightBall.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib.IClients;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class EightBall : ModuleBase
|
||||
{
|
||||
private readonly IRandomClient rnd;
|
||||
public EightBall(IRandomClient randomClient)
|
||||
{
|
||||
rnd = randomClient;
|
||||
}
|
||||
[Command("8ball", RunMode = RunMode.Async), Summary("Ask 8Ball a Question.")]
|
||||
public async Task Ball([Remainder, Summary("The Question")] string echo)
|
||||
{
|
||||
var replies = new List<string> {
|
||||
"It is certain",
|
||||
"It is decidedly so",
|
||||
"Without a doubt",
|
||||
"Yes, definitely",
|
||||
"You may rely on it",
|
||||
"As I see it, yes",
|
||||
"Most likely",
|
||||
"Outlook good",
|
||||
"Yes",
|
||||
"Signs point to yes",
|
||||
"Reply hazy try again",
|
||||
"Ask again later",
|
||||
"Better not tell you now",
|
||||
"Cannot predict now",
|
||||
"Concentrate and ask again",
|
||||
"Don't count on it",
|
||||
"My reply is no",
|
||||
"My sources say no",
|
||||
"Outlook not so good",
|
||||
"Very doubtful"};
|
||||
|
||||
var answer = rnd.Client.Next(replies.Count);
|
||||
await ReplyAsync(replies[answer]);
|
||||
}
|
||||
}
|
||||
}
|
47
Geekbot.net/Modules/GuildInfo.cs
Normal file
47
Geekbot.net/Modules/GuildInfo.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Discord;
|
||||
using Geekbot.net.Lib;
|
||||
using System.Linq;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class GuildInfo : ModuleBase
|
||||
{
|
||||
private readonly IRedisClient redis;
|
||||
public GuildInfo(IRedisClient redisClient)
|
||||
{
|
||||
redis = redisClient;
|
||||
}
|
||||
|
||||
[Command("serverstats", RunMode = RunMode.Async), Summary("Show some info about the bot.")]
|
||||
public async Task getInfo()
|
||||
{
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithAuthor(new EmbedAuthorBuilder()
|
||||
.WithIconUrl(Context.Guild.IconUrl)
|
||||
.WithName(Context.Guild.Name));
|
||||
eb.WithColor(new Color(110, 204, 147));
|
||||
|
||||
var created = Context.Guild.CreatedAt;
|
||||
var age = Math.Floor((DateTime.Now - created).TotalDays);
|
||||
|
||||
var messages = redis.Client.StringGet($"{Context.Guild.Id}-messages");
|
||||
var level = LevelCalc.GetLevelAtExperience((int)messages);
|
||||
|
||||
eb.AddField("Server Age", $"{created.Day}/{created.Month}/{created.Year} ({age} days)");
|
||||
eb.AddInlineField("Level", level)
|
||||
.AddInlineField("Messages", messages);
|
||||
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
|
||||
public static string FirstCharToUpper(string input)
|
||||
{
|
||||
if (String.IsNullOrEmpty(input))
|
||||
throw new ArgumentException("ARGH!");
|
||||
return input.First().ToString().ToUpper() + input.Substring(1);
|
||||
}
|
||||
}
|
||||
}
|
27
Geekbot.net/Modules/Help.cs
Normal file
27
Geekbot.net/Modules/Help.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class Help : ModuleBase
|
||||
{
|
||||
[Command("help", RunMode = RunMode.Async), Summary("List all Commands")]
|
||||
public async Task GetHelp()
|
||||
{
|
||||
var commands = new CommandService();
|
||||
await commands.AddModulesAsync(Assembly.GetEntryAssembly());
|
||||
var cmdList = commands.Commands;
|
||||
var reply = "**Geekbot Command list**\r\n";
|
||||
foreach (var cmd in cmdList)
|
||||
{
|
||||
var param = string.Join(", !",cmd.Aliases);
|
||||
if (!param.Contains("admin"))
|
||||
{
|
||||
reply = reply + $"**{cmd.Name}** (!{param}) - {cmd.Summary}\r\n";
|
||||
}
|
||||
}
|
||||
await ReplyAsync(reply);
|
||||
}
|
||||
}
|
||||
}
|
37
Geekbot.net/Modules/Info.cs
Normal file
37
Geekbot.net/Modules/Info.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class Info : ModuleBase
|
||||
{
|
||||
private readonly IRedisClient redis;
|
||||
public Info(IRedisClient redisClient)
|
||||
{
|
||||
redis = redisClient;
|
||||
}
|
||||
|
||||
[Command("info", RunMode = RunMode.Async), Summary("Get Information about the bot")]
|
||||
public async Task BotInfo()
|
||||
{
|
||||
var eb = new EmbedBuilder();
|
||||
|
||||
eb.WithTitle("Geekbot V3");
|
||||
|
||||
var botOwner = Context.Guild.GetUserAsync(ulong.Parse(redis.Client.StringGet("botOwner"))).Result;
|
||||
|
||||
eb.AddInlineField("Status", Context.Client.ConnectionState.ToString())
|
||||
.AddInlineField("Bot Name", Context.Client.CurrentUser.Username)
|
||||
.AddInlineField("Bot Owner", $"{botOwner.Username}#{botOwner.Discriminator}");
|
||||
|
||||
eb.AddInlineField("Servers", Context.Client.GetGuildsAsync().Result.Count);
|
||||
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +1,12 @@
|
|||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Utils
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class Ping : TransactionModuleBase
|
||||
public class Ping : ModuleBase
|
||||
{
|
||||
[Command("👀", RunMode = RunMode.Async)]
|
||||
[Summary("Look at the bot.")]
|
||||
[Command("👀", RunMode = RunMode.Async), Summary("Look at the bot.")]
|
||||
public async Task Eyes()
|
||||
{
|
||||
await ReplyAsync("S... Stop looking at me... baka!");
|
48
Geekbot.net/Modules/Roll.cs
Normal file
48
Geekbot.net/Modules/Roll.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
using Geekbot.net.Lib.IClients;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class Roll : ModuleBase
|
||||
{
|
||||
private readonly IRedisClient redis;
|
||||
private readonly IRandomClient rnd;
|
||||
public Roll(IRedisClient redisClient, IRandomClient randomClient)
|
||||
{
|
||||
redis = redisClient;
|
||||
rnd = randomClient;
|
||||
}
|
||||
|
||||
[Command("roll", RunMode = RunMode.Async), Summary("Roll a number between 1 and 100.")]
|
||||
public async Task RollCommand([Remainder, Summary("stuff...")] string stuff = "nothing")
|
||||
{
|
||||
var number = rnd.Client.Next(1, 100);
|
||||
var guess = 1000;
|
||||
int.TryParse(stuff, out guess);
|
||||
if (guess <= 100 && guess > 0)
|
||||
{
|
||||
await ReplyAsync($"{Context.Message.Author.Mention} you rolled {number}, your guess was {guess}");
|
||||
if (guess == number)
|
||||
{
|
||||
await ReplyAsync($"Congratulations {Context.User.Username}, your guess was correct!");
|
||||
var key = $"{Context.Guild.Id}-{Context.User.Id}-correctRolls";
|
||||
var messages = (int)redis.Client.StringGet(key);
|
||||
redis.Client.StringSet(key, (messages + 1).ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("dice", RunMode = RunMode.Async), Summary("Roll a dice")]
|
||||
public async Task DiceCommand([Summary("The highest number on the dice")] int max = 6)
|
||||
{
|
||||
var number = rnd.Client.Next(1, max);
|
||||
await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number);
|
||||
}
|
||||
}
|
||||
}
|
16
Geekbot.net/Modules/Say.cs
Normal file
16
Geekbot.net/Modules/Say.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class Say : ModuleBase
|
||||
{
|
||||
[RequireUserPermission(Discord.GuildPermission.Administrator)]
|
||||
[Command("say", RunMode = RunMode.Async), Summary("Say Something.")]
|
||||
public async Task Echo([Remainder, Summary("What?")] string echo)
|
||||
{
|
||||
await Context.Message.DeleteAsync();
|
||||
await ReplyAsync(echo);
|
||||
}
|
||||
}
|
||||
}
|
57
Geekbot.net/Modules/UserInfo.cs
Normal file
57
Geekbot.net/Modules/UserInfo.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class UserInfo : ModuleBase
|
||||
{
|
||||
private readonly IRedisClient redis;
|
||||
public UserInfo(IRedisClient redisClient)
|
||||
{
|
||||
redis = redisClient;
|
||||
}
|
||||
|
||||
[Alias("stats")]
|
||||
[Command("user", RunMode = RunMode.Async), Summary("Get information about this user")]
|
||||
public async Task User([Summary("The (optional) user to get info for")] IUser user = null)
|
||||
{
|
||||
var userInfo = user ?? Context.Message.Author;
|
||||
|
||||
var age = Math.Floor((DateTime.Now - userInfo.CreatedAt).TotalDays);
|
||||
|
||||
var key = Context.Guild.Id + "-" + userInfo.Id;
|
||||
var messages = (int)redis.Client.StringGet(key + "-messages");
|
||||
var level = LevelCalc.GetLevelAtExperience(messages);
|
||||
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithAuthor(new EmbedAuthorBuilder()
|
||||
.WithIconUrl(userInfo.GetAvatarUrl())
|
||||
.WithName(userInfo.Username));
|
||||
|
||||
eb.WithColor(new Color(221, 255, 119));
|
||||
|
||||
eb.AddField("Discordian Since", $"{userInfo.CreatedAt.Day}/{userInfo.CreatedAt.Month}/{userInfo.CreatedAt.Year} ({age} days)");
|
||||
eb.AddInlineField("Level", level)
|
||||
.AddInlineField("Messages Sent", messages);
|
||||
|
||||
var karma = redis.Client.StringGet(key + "-karma");
|
||||
if (!karma.IsNullOrEmpty)
|
||||
{
|
||||
eb.AddField("Karma", karma);
|
||||
}
|
||||
|
||||
var correctRolls = redis.Client.StringGet($"{Context.Guild.Id}-{userInfo.Id}-correctRolls");
|
||||
if (!correctRolls.IsNullOrEmpty)
|
||||
{
|
||||
eb.AddField("Guessed Rolls", correctRolls);
|
||||
}
|
||||
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
56
Geekbot.net/Modules/Youtube.cs
Normal file
56
Geekbot.net/Modules/Youtube.cs
Normal file
|
@ -0,0 +1,56 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
using Google.Apis.Services;
|
||||
using Google.Apis.YouTube.v3;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class Youtube : ModuleBase
|
||||
{
|
||||
private readonly IRedisClient redis;
|
||||
public Youtube(IRedisClient redisClient)
|
||||
{
|
||||
redis = redisClient;
|
||||
}
|
||||
|
||||
[Command("yt", RunMode = RunMode.Async), Summary("Search for something on youtube.")]
|
||||
public async Task Yt([Remainder, Summary("A Song Title")] string searchQuery)
|
||||
{
|
||||
var key = redis.Client.StringGet("youtubeKey");
|
||||
if (key.IsNullOrEmpty)
|
||||
{
|
||||
await ReplyAsync("No youtube key set, please tell my senpai to set one");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
|
||||
{
|
||||
ApiKey = key.ToString(),
|
||||
ApplicationName = this.GetType().ToString()
|
||||
});
|
||||
|
||||
var searchListRequest = youtubeService.Search.List("snippet");
|
||||
searchListRequest.Q = searchQuery;
|
||||
searchListRequest.MaxResults = 2;
|
||||
|
||||
var searchListResponse = await searchListRequest.ExecuteAsync();
|
||||
|
||||
var result = searchListResponse.Items[0];
|
||||
|
||||
await ReplyAsync(
|
||||
$"\"{result.Snippet.Title}\" from \"{result.Snippet.ChannelTitle}\" https://youtu.be/{result.Id.VideoId}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ReplyAsync("Something went wrong... informing my senpai...");
|
||||
var botOwner = Context.Guild.GetUserAsync(ulong.Parse(redis.Client.StringGet("botOwner"))).Result;
|
||||
var dm = await botOwner.CreateDMChannelAsync();
|
||||
await dm.SendMessageAsync($"Something went wrong while getting a video from youtube:\r\n```\r\n{e.Message}\r\n```");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
163
Geekbot.net/Program.cs
Executable file
163
Geekbot.net/Program.cs
Executable file
|
@ -0,0 +1,163 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using Geekbot.net.Lib;
|
||||
using Geekbot.net.Lib.IClients;
|
||||
using Geekbot.net.Modules;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Geekbot.net
|
||||
{
|
||||
class Program
|
||||
{
|
||||
private CommandService commands;
|
||||
private DiscordSocketClient client;
|
||||
private DependencyMap map;
|
||||
private IRedisClient redis;
|
||||
private RedisValue token;
|
||||
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(@" ____ _____ _____ _ ______ ___ _____");
|
||||
Console.WriteLine(@" / ___| ____| ____| |/ / __ ) / _ \\_ _|");
|
||||
Console.WriteLine(@"| | _| _| | _| | ' /| _ \| | | || |");
|
||||
Console.WriteLine(@"| |_| | |___| |___| . \| |_) | |_| || |");
|
||||
Console.WriteLine(@" \____|_____|_____|_|\_\____/ \___/ |_|");
|
||||
Console.WriteLine("=========================================");
|
||||
Console.WriteLine("Starting...");
|
||||
|
||||
Task.WaitAll(new Program().MainAsync());
|
||||
}
|
||||
|
||||
public async Task MainAsync()
|
||||
{
|
||||
client = new DiscordSocketClient();
|
||||
commands = new CommandService();
|
||||
redis = new RedisClient();
|
||||
|
||||
token = redis.Client.StringGet("discordToken");
|
||||
if (token.IsNullOrEmpty)
|
||||
{
|
||||
Console.Write("Your bot Token: ");
|
||||
var newToken = Console.ReadLine();
|
||||
redis.Client.StringSet("discordToken", newToken);
|
||||
token = newToken;
|
||||
|
||||
Console.Write("Bot Owner User ID: ");
|
||||
var ownerId = Console.ReadLine();
|
||||
redis.Client.StringSet("botOwner", ownerId);
|
||||
}
|
||||
|
||||
map = new DependencyMap();
|
||||
map.Add<ICatClient>(new CatClient());
|
||||
map.Add(redis);
|
||||
map.Add<IRandomClient>(new RandomClient());
|
||||
|
||||
Console.WriteLine("Connecting to Discord...");
|
||||
|
||||
await Login();
|
||||
|
||||
await Task.Delay(-1);
|
||||
}
|
||||
|
||||
public async Task Login()
|
||||
{
|
||||
try
|
||||
{
|
||||
await client.LoginAsync(TokenType.Bot, token);
|
||||
await client.StartAsync();
|
||||
client.Connected += FinishStartup;
|
||||
}
|
||||
catch (AggregateException)
|
||||
{
|
||||
Console.WriteLine("Could not connect to discord...");
|
||||
Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Reconnect(Exception exception)
|
||||
{
|
||||
Console.WriteLine("=========================================");
|
||||
Console.WriteLine("Geekbot Disconnected from the Discord Gateway...");
|
||||
Console.WriteLine(exception.Message);
|
||||
Console.WriteLine("Attempting Reconnect...");
|
||||
Console.WriteLine("=========================================");
|
||||
await client.StopAsync();
|
||||
System.Threading.Thread.Sleep(10000);
|
||||
await Login();
|
||||
}
|
||||
|
||||
public async Task FinishStartup()
|
||||
{
|
||||
await client.SetGameAsync("Ping Pong");
|
||||
Console.WriteLine($"Now Connected to {client.Guilds.Count} Servers");
|
||||
|
||||
Console.WriteLine("Registering Stuff");
|
||||
|
||||
client.MessageReceived += HandleCommand;
|
||||
client.MessageReceived += HandleMessageReceived;
|
||||
client.UserJoined += HandleUserJoined;
|
||||
// client.Disconnected += Reconnect;
|
||||
await commands.AddModulesAsync(Assembly.GetEntryAssembly());
|
||||
|
||||
Console.WriteLine("Done and ready for use...\n");
|
||||
}
|
||||
|
||||
public async Task HandleCommand(SocketMessage messageParam)
|
||||
{
|
||||
var message = messageParam as SocketUserMessage;
|
||||
if (message == null) return;
|
||||
if (message.Author.Username.Equals(client.CurrentUser.Username)) return;
|
||||
int argPos = 0;
|
||||
if (message.ToString().ToLower().StartsWith("ping"))
|
||||
{
|
||||
await message.Channel.SendMessageAsync("pong");
|
||||
return;
|
||||
}
|
||||
if (message.ToString().ToLower().StartsWith("hui"))
|
||||
{
|
||||
await message.Channel.SendMessageAsync("hui!!!");
|
||||
return;
|
||||
}
|
||||
if (message.ToString().ToLower().Contains("teamspeak") || message.ToString().ToLower().Contains("skype"))
|
||||
{
|
||||
await message.Channel.SendMessageAsync("How dare you to use such a filthy word in here http://bit.ly/2poL2IZ");
|
||||
return;
|
||||
}
|
||||
if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos))) return;
|
||||
var context = new CommandContext(client, message);
|
||||
Task.Run(async () => await commands.ExecuteAsync(context, argPos, map));
|
||||
}
|
||||
|
||||
public async Task HandleMessageReceived(SocketMessage messsageParam)
|
||||
{
|
||||
var message = messsageParam;
|
||||
if (message == null) return;
|
||||
|
||||
var channel = (SocketGuildChannel)message.Channel;
|
||||
|
||||
Console.WriteLine(channel.Guild.Name + " - " + message.Channel + " - " + message.Author.Username + " - " + message.Content);
|
||||
|
||||
var statsRecorder = new StatsRecorder(message, redis);
|
||||
Task.Run(() => statsRecorder.UpdateUserRecordAsync());
|
||||
Task.Run(() => statsRecorder.UpdateGuildRecordAsync());
|
||||
}
|
||||
|
||||
public async Task HandleUserJoined(SocketGuildUser user)
|
||||
{
|
||||
if (!user.IsBot)
|
||||
{
|
||||
var message = redis.Client.StringGet(user.Guild.Id + "-welcomeMsg");
|
||||
if (!message.IsNullOrEmpty)
|
||||
{
|
||||
message = message.ToString().Replace("$user", user.Mention);
|
||||
await user.Guild.DefaultChannel.SendMessageAsync(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
674
LICENSE
674
LICENSE
|
@ -1,674 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
25
Tests/Tests.csproj
Executable file
25
Tests/Tests.csproj
Executable file
|
@ -0,0 +1,25 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions">
|
||||
<Version>4.19.2</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
|
||||
<PackageReference Include="Moq">
|
||||
<Version>4.7.8</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="RestSharp.NetCore">
|
||||
<Version>105.2.4-rc4-24214-01</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="xunit" Version="2.2.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Geekbot.net\Geekbot.net.csproj">
|
||||
<Project>{FDCB3D92-E7B5-47BB-A9B5-CFAEFA57CDB4}</Project>
|
||||
<Name>Geekbot.net</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
52
Tests/UnitTest1.cs
Executable file
52
Tests/UnitTest1.cs
Executable file
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Geekbot.net.Lib;
|
||||
using Geekbot.net.Modules;
|
||||
using Moq;
|
||||
using RestSharp;
|
||||
using Xunit;
|
||||
|
||||
namespace Tests
|
||||
{
|
||||
public class UnitTest1
|
||||
{
|
||||
[Fact]
|
||||
public async Task TestCat()
|
||||
{
|
||||
// setup
|
||||
var catClient = new Mock<ICatClient>(MockBehavior.Strict);
|
||||
var client = new Mock<IRestClient>(MockBehavior.Strict);
|
||||
catClient.Setup(cc => cc.Client).Returns(client.Object);
|
||||
var response = new Mock<IRestResponse<Cat.CatResponse>>(MockBehavior.Strict);
|
||||
var resultData = new Cat.CatResponse {file = "unit-test"};
|
||||
response.SetupGet(r => r.Data).Returns(resultData);
|
||||
Console.WriteLine(resultData.file);
|
||||
var request = new Mock<IRestRequest>(MockBehavior.Strict);
|
||||
Func<IRestRequest> requestFunc = () => request.Object;
|
||||
client.Setup(c => c.Execute<Cat.CatResponse>(request.Object)).Returns(response.Object);
|
||||
Mock<AsyncReplier> asyncReplier = new Mock<AsyncReplier>(MockBehavior.Strict);
|
||||
asyncReplier.Setup(ar => ar.ReplyAsyncInt(resultData.file)).Returns(Task.FromResult(true)).Verifiable();
|
||||
|
||||
// execute
|
||||
//var cat = new Cat(catClient.Object, requestFunc, asyncReplier.Object);
|
||||
//await cat.Say();
|
||||
|
||||
// validate
|
||||
//asyncReplier.Verify();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 0)]
|
||||
[InlineData(33, 4561)]
|
||||
[InlineData(79, 449702)]
|
||||
[InlineData(79, 449702 + 1)]
|
||||
public void TestLevel(int expectedIndex, int experience)
|
||||
{
|
||||
var index = LevelCalc.GetLevelAtExperience(experience);
|
||||
index.Should().Be(expectedIndex);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
collections:
|
||||
- name: community.docker
|
||||
version: 2.7.0
|
30
readme.md
30
readme.md
|
@ -1,29 +1,13 @@
|
|||
[![pipeline status](https://gitlab.com/dbgit/open/geekbot/badges/master/pipeline.svg)](https://gitlab.com/dbgit/open/geekbot/commits/master)
|
||||
# Geekbot.net
|
||||
|
||||
# [Geekbot.net](https://geekbot.pizzaandcoffee.rocks/)
|
||||
The Geekbot rewritten in C# and dotnet core
|
||||
|
||||
A General Purpose Discord Bot written in C#
|
||||
### Running
|
||||
|
||||
You can invite Geekbot to your server with [this link](https://discordapp.com/oauth2/authorize?client_id=171249478546882561&scope=bot&permissions=1416834054)
|
||||
Geekbot.net Requires dotnet core 1.0.1 and dotnet core cli 1.1
|
||||
|
||||
## Technologies
|
||||
`dotnet restore`
|
||||
|
||||
* .NET 5
|
||||
* PostgreSQL
|
||||
* Discord.net
|
||||
`cd Geekbot.net`
|
||||
|
||||
## Running
|
||||
|
||||
You can start geekbot with: `dotnet run`
|
||||
|
||||
On your first run geekbot will ask for your bot token.
|
||||
|
||||
You might need to pass some additional configuration (e.g. database credentials), these can be passed as commandline arguments or environment variables.
|
||||
|
||||
For a list of commandline arguments and environment variables use `dotnet run -- -h`
|
||||
|
||||
All Environment Variables must be prefixed with `GEEKBOT_`
|
||||
|
||||
## Contributing
|
||||
|
||||
Everyone is free to open an issue or create a pull request
|
||||
`dotnet run`
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
|
||||
<RootNamespace>Geekbot.Bot</RootNamespace>
|
||||
<AssemblyName>Geekbot.Bot</AssemblyName>
|
||||
<Version Condition=" '$(VersionSuffix)' != '' ">$(VersionSuffix)</Version>
|
||||
<Version Condition=" '$(VersionSuffix)' == '' ">0.0.0-DEV</Version>
|
||||
<NoWarn>NU1701</NoWarn>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||
<OutputType>Library</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineParser" Version="2.8.0" />
|
||||
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.45.0.1929" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.36" />
|
||||
<PackageReference Include="JikanDotNet" Version="1.6.0" />
|
||||
<PackageReference Include="MtgApiManager.Lib" Version="1.2.2" />
|
||||
<PackageReference Include="PokeApi.NET" Version="1.1.2" />
|
||||
<PackageReference Include="Sentry" Version="3.11.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Storage\*">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Commands\Commands.csproj" />
|
||||
<ProjectReference Include="..\Core\Core.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,127 +0,0 @@
|
|||
using System.Reflection;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using Geekbot.Bot.Handlers;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.GlobalSettings;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
using Geekbot.Core.Logger;
|
||||
using Geekbot.Core.Logger.Adapters;
|
||||
using Geekbot.Core.ReactionListener;
|
||||
using Geekbot.Core.UserRepository;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Geekbot.Bot;
|
||||
|
||||
public class BotStartup
|
||||
{
|
||||
private readonly IServiceCollection _serviceCollection;
|
||||
private readonly GeekbotLogger _logger;
|
||||
private readonly RunParameters _runParameters;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private DiscordSocketClient _client;
|
||||
|
||||
public BotStartup(IServiceCollection serviceCollection, GeekbotLogger logger, RunParameters runParameters, IGlobalSettings globalSettings)
|
||||
{
|
||||
_serviceCollection = serviceCollection;
|
||||
_logger = logger;
|
||||
_runParameters = runParameters;
|
||||
_globalSettings = globalSettings;
|
||||
}
|
||||
|
||||
public async Task Start()
|
||||
{
|
||||
_logger.Information(LogSource.Geekbot, "Connecting to Discord");
|
||||
SetupDiscordClient();
|
||||
await Login();
|
||||
await _client.SetGameAsync(_globalSettings.GetKey("Game"));
|
||||
_logger.Information(LogSource.Geekbot, $"Now Connected as {_client.CurrentUser.Username} to {_client.Guilds.Count} Servers");
|
||||
|
||||
_logger.Information(LogSource.Geekbot, "Registering Gateway Handlers");
|
||||
await RegisterHandlers();
|
||||
|
||||
_logger.Information(LogSource.Geekbot, "Done and ready for use");
|
||||
await Task.Delay(-1);
|
||||
}
|
||||
|
||||
private void SetupDiscordClient()
|
||||
{
|
||||
_client = new DiscordSocketClient(new DiscordSocketConfig
|
||||
{
|
||||
GatewayIntents = GatewayIntents.DirectMessageReactions |
|
||||
GatewayIntents.DirectMessages |
|
||||
GatewayIntents.GuildMessageReactions |
|
||||
GatewayIntents.GuildMessages |
|
||||
GatewayIntents.GuildWebhooks |
|
||||
GatewayIntents.GuildIntegrations |
|
||||
GatewayIntents.GuildEmojis |
|
||||
GatewayIntents.GuildBans |
|
||||
GatewayIntents.Guilds |
|
||||
GatewayIntents.GuildMembers,
|
||||
LogLevel = LogSeverity.Verbose,
|
||||
MessageCacheSize = 1000,
|
||||
});
|
||||
|
||||
var discordLogger = new DiscordLogger(_logger);
|
||||
_client.Log += discordLogger.Log;
|
||||
}
|
||||
|
||||
private async Task Login()
|
||||
{
|
||||
try
|
||||
{
|
||||
var token = await GetToken();
|
||||
await _client.LoginAsync(TokenType.Bot, token);
|
||||
await _client.StartAsync();
|
||||
while (!_client.ConnectionState.Equals(ConnectionState.Connected)) await Task.Delay(25);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(LogSource.Geekbot, "Could not connect to Discord", e);
|
||||
Environment.Exit(GeekbotExitCode.CouldNotLogin.GetHashCode());
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<string> GetToken()
|
||||
{
|
||||
var token = _runParameters.Token ?? _globalSettings.GetKey("DiscordToken");
|
||||
if (string.IsNullOrEmpty(token))
|
||||
{
|
||||
Console.Write("Your bot Token: ");
|
||||
var newToken = Console.ReadLine();
|
||||
await _globalSettings.SetKey("DiscordToken", newToken);
|
||||
await _globalSettings.SetKey("Game", "Ping Pong");
|
||||
token = newToken;
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
private async Task RegisterHandlers()
|
||||
{
|
||||
var applicationInfo = await _client.GetApplicationInfoAsync();
|
||||
|
||||
_serviceCollection.AddSingleton<DiscordSocketClient>(_client);
|
||||
var serviceProvider = _serviceCollection.BuildServiceProvider();
|
||||
|
||||
var commands = new CommandService();
|
||||
await commands.AddModulesAsync(Assembly.GetAssembly(typeof(BotStartup)), serviceProvider);
|
||||
|
||||
var commandHandler = new CommandHandler(_client, _logger, serviceProvider, commands, applicationInfo, serviceProvider.GetService<IGuildSettingsManager>());
|
||||
var userHandler = new UserHandler(serviceProvider.GetService<IUserRepository>(), _logger, serviceProvider.GetService<DatabaseContext>(), _client);
|
||||
var reactionHandler = new ReactionHandler(serviceProvider.GetService<IReactionListener>());
|
||||
var statsHandler = new StatsHandler(_logger, serviceProvider.GetService<DatabaseContext>());
|
||||
var messageDeletedHandler = new MessageDeletedHandler(serviceProvider.GetService<DatabaseContext>(), _logger, _client);
|
||||
|
||||
_client.MessageReceived += commandHandler.RunCommand;
|
||||
_client.MessageDeleted += messageDeletedHandler.HandleMessageDeleted;
|
||||
_client.UserJoined += userHandler.Joined;
|
||||
_client.UserUpdated += userHandler.Updated;
|
||||
_client.UserLeft += userHandler.Left;
|
||||
_client.ReactionAdded += reactionHandler.Added;
|
||||
_client.ReactionRemoved += reactionHandler.Removed;
|
||||
if (!_runParameters.InMemory) _client.MessageReceived += statsHandler.UpdateStats;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
|
||||
namespace Geekbot.Bot.CommandPreconditions
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
|
||||
public class DisableInDirectMessageAttribute : PreconditionAttribute
|
||||
{
|
||||
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
|
||||
{
|
||||
var result = context.Guild.Id != 0 ? PreconditionResult.FromSuccess() : PreconditionResult.FromError("Command unavailable in Direct Messaging");
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,253 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Resources;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using Geekbot.Bot.CommandPreconditions;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.Extensions;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
using Localization = Geekbot.Core.Localization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Admin
|
||||
{
|
||||
[Group("admin")]
|
||||
[RequireUserPermission(GuildPermission.Administrator)]
|
||||
[DisableInDirectMessage]
|
||||
public class Admin : GeekbotCommandBase
|
||||
{
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
||||
public Admin(DiscordSocketClient client, IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
|
||||
[Command("welcome", RunMode = RunMode.Async)]
|
||||
[Summary("Set a Welcome Message (use '$user' to mention the new joined user).")]
|
||||
public async Task SetWelcomeMessage([Remainder, Summary("message")] string welcomeMessage)
|
||||
{
|
||||
GuildSettings.WelcomeMessage = welcomeMessage;
|
||||
await GuildSettingsManager.UpdateSettings(GuildSettings);
|
||||
|
||||
var formatedMessage = welcomeMessage.Replace("$user", Context.User.Mention);
|
||||
await ReplyAsync($"Welcome message has been changed\r\nHere is an example of how it would look:\r\n{formatedMessage}");
|
||||
}
|
||||
|
||||
[Command("welcomechannel", RunMode = RunMode.Async)]
|
||||
[Summary("Set a channel for the welcome messages (by default it uses the top most channel)")]
|
||||
public async Task SelectWelcomeChannel([Summary("#Channel")] ISocketMessageChannel channel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var m = await channel.SendMessageAsync("...");
|
||||
|
||||
GuildSettings.WelcomeChannel = channel.Id.AsLong();
|
||||
await GuildSettingsManager.UpdateSettings(GuildSettings);
|
||||
|
||||
await m.DeleteAsync();
|
||||
|
||||
await ReplyAsync("Successfully saved the welcome channel");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context, "That channel doesn't seem to exist or i don't have write permissions");
|
||||
}
|
||||
}
|
||||
|
||||
[Command("modchannel", RunMode = RunMode.Async)]
|
||||
[Summary("Set a channel for moderation purposes")]
|
||||
public async Task SelectModChannel([Summary("#Channel")] ISocketMessageChannel channel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var m = await channel.SendMessageAsync("verifying...");
|
||||
|
||||
GuildSettings.ModChannel = channel.Id.AsLong();
|
||||
await GuildSettingsManager.UpdateSettings(GuildSettings);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine("Successfully saved mod channel, you can now do the following");
|
||||
sb.AppendLine("- `!admin showleave` - send message to mod channel when someone leaves");
|
||||
sb.AppendLine("- `!admin showdel` - send message to mod channel when someone deletes a message");
|
||||
await m.ModifyAsync(e => e.Content = sb.ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context, "That channel doesn't seem to exist or i don't have write permissions");
|
||||
}
|
||||
}
|
||||
|
||||
[Command("showleave", RunMode = RunMode.Async)]
|
||||
[Summary("Toggle - notify modchannel when someone leaves")]
|
||||
public async Task ShowLeave()
|
||||
{
|
||||
try
|
||||
{
|
||||
var modChannel = await GetModChannel(GuildSettings.ModChannel.AsUlong());
|
||||
if (modChannel == null) return;
|
||||
|
||||
GuildSettings.ShowLeave = !GuildSettings.ShowLeave;
|
||||
await GuildSettingsManager.UpdateSettings(GuildSettings);
|
||||
await modChannel.SendMessageAsync(GuildSettings.ShowLeave
|
||||
? "Saved - now sending messages here when someone leaves"
|
||||
: "Saved - stopping sending messages here when someone leaves"
|
||||
);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("showdel", RunMode = RunMode.Async)]
|
||||
[Summary("Toggle - notify modchannel when someone deletes a message")]
|
||||
public async Task ShowDelete()
|
||||
{
|
||||
try
|
||||
{
|
||||
var modChannel = await GetModChannel(GuildSettings.ModChannel.AsUlong());
|
||||
if (modChannel == null) return;
|
||||
|
||||
GuildSettings.ShowDelete = !GuildSettings.ShowDelete;
|
||||
await GuildSettingsManager.UpdateSettings(GuildSettings);
|
||||
await modChannel.SendMessageAsync(GuildSettings.ShowDelete
|
||||
? "Saved - now sending messages here when someone deletes a message"
|
||||
: "Saved - stopping sending messages here when someone deletes a message"
|
||||
);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("setlang", RunMode = RunMode.Async)]
|
||||
[Summary("Change the bots language")]
|
||||
public async Task SetLanguage([Summary("language")] string language)
|
||||
{
|
||||
try
|
||||
{
|
||||
var availableLanguages = new List<string>();
|
||||
availableLanguages.Add("en-GB"); // default
|
||||
availableLanguages.AddRange(GetAvailableCultures().Select(culture => culture.Name));
|
||||
if (availableLanguages.Contains(language))
|
||||
{
|
||||
GuildSettings.Language = language;
|
||||
await GuildSettingsManager.UpdateSettings(GuildSettings);
|
||||
|
||||
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(language.ToLower() == "chde" ? "de-CH" : language);
|
||||
|
||||
await ReplyAsync(Localization.Admin.NewLanguageSet);
|
||||
return;
|
||||
}
|
||||
|
||||
await ReplyAsync($"That doesn't seem to be a supported language\nSupported Languages are {string.Join(", ", availableLanguages)}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("wiki", RunMode = RunMode.Async)]
|
||||
[Summary("Change the wikipedia instance (use lang code in xx.wikipedia.org)")]
|
||||
public async Task SetWikiLanguage([Summary("language")] string languageRaw)
|
||||
{
|
||||
try
|
||||
{
|
||||
var language = languageRaw.ToLower();
|
||||
GuildSettings.WikiLang = language;
|
||||
await GuildSettingsManager.UpdateSettings(GuildSettings);
|
||||
|
||||
await ReplyAsync($"Now using the {language} wikipedia");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("ping", RunMode = RunMode.Async)]
|
||||
[Summary("Enable the ping reply.")]
|
||||
public async Task TogglePing()
|
||||
{
|
||||
try
|
||||
{
|
||||
// var guild = _guildSettingsManager.GetSettings(Context.Guild.Id);
|
||||
GuildSettings.Ping = !GuildSettings.Ping;
|
||||
await GuildSettingsManager.UpdateSettings(GuildSettings);
|
||||
await ReplyAsync(GuildSettings.Ping ? "i will reply to ping now" : "No more pongs...");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("hui", RunMode = RunMode.Async)]
|
||||
[Summary("Enable the ping reply.")]
|
||||
public async Task ToggleHui()
|
||||
{
|
||||
try
|
||||
{
|
||||
// var guild = _guildSettingsManager.GetSettings(Context.Guild.Id);
|
||||
GuildSettings.Hui = !GuildSettings.Hui;
|
||||
await GuildSettingsManager.UpdateSettings(GuildSettings);
|
||||
await ReplyAsync(GuildSettings.Hui ? "i will reply to hui now" : "No more hui's...");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<ISocketMessageChannel> GetModChannel(ulong channelId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (channelId == ulong.MinValue) throw new Exception();
|
||||
var modChannel = (ISocketMessageChannel) _client.GetChannel(channelId);
|
||||
if (modChannel == null) throw new Exception();
|
||||
return modChannel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
await ReplyAsync("Modchannel doesn't seem to exist, please set one with `!admin modchannel [channelId]`");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<CultureInfo> GetAvailableCultures()
|
||||
{
|
||||
var result = new List<CultureInfo>();
|
||||
var rm = new ResourceManager(typeof(Localization.Admin));
|
||||
var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
|
||||
foreach (var culture in cultures)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (culture.Equals(CultureInfo.InvariantCulture)) continue; //do not use "==", won't work
|
||||
|
||||
var rs = rm.GetResourceSet(culture, true, false);
|
||||
if (rs != null)
|
||||
{
|
||||
result.Add(culture);
|
||||
}
|
||||
}
|
||||
catch (CultureNotFoundException)
|
||||
{
|
||||
//NOP
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.GlobalSettings;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
using Geekbot.Core.Logger;
|
||||
using Geekbot.Core.UserRepository;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Admin.Owner
|
||||
{
|
||||
[Group("owner")]
|
||||
[RequireOwner]
|
||||
public class Owner : GeekbotCommandBase
|
||||
{
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IGeekbotLogger _logger;
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
public Owner(DiscordSocketClient client, IGeekbotLogger logger, IUserRepository userRepositry, IErrorHandler errorHandler, IGlobalSettings globalSettings,
|
||||
IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager)
|
||||
{
|
||||
_client = client;
|
||||
_logger = logger;
|
||||
_userRepository = userRepositry;
|
||||
_globalSettings = globalSettings;
|
||||
}
|
||||
|
||||
[Command("youtubekey", RunMode = RunMode.Async)]
|
||||
[Summary("Set the youtube api key")]
|
||||
public async Task SetYoutubeKey([Summary("API-Key")] string key)
|
||||
{
|
||||
await _globalSettings.SetKey("YoutubeKey", key);
|
||||
await ReplyAsync("Apikey has been set");
|
||||
}
|
||||
|
||||
[Command("game", RunMode = RunMode.Async)]
|
||||
[Summary("Set the game that the bot is playing")]
|
||||
public async Task SetGame([Remainder] [Summary("Game")] string key)
|
||||
{
|
||||
await _globalSettings.SetKey("Game", key);
|
||||
await _client.SetGameAsync(key);
|
||||
_logger.Information(LogSource.Geekbot, $"Changed game to {key}");
|
||||
await ReplyAsync($"Now Playing {key}");
|
||||
}
|
||||
|
||||
[Command("popuserrepo", RunMode = RunMode.Async)]
|
||||
[Summary("Populate user cache")]
|
||||
public async Task PopUserRepoCommand()
|
||||
{
|
||||
var success = 0;
|
||||
var failed = 0;
|
||||
try
|
||||
{
|
||||
_logger.Warning(LogSource.UserRepository, "Populating User Repositry");
|
||||
await ReplyAsync("Starting Population of User Repository");
|
||||
foreach (var guild in _client.Guilds)
|
||||
{
|
||||
_logger.Information(LogSource.UserRepository, $"Populating users from {guild.Name}");
|
||||
foreach (var user in guild.Users)
|
||||
{
|
||||
var succeded = await _userRepository.Update(user);
|
||||
var inc = succeded ? success++ : failed++;
|
||||
}
|
||||
}
|
||||
|
||||
_logger.Warning(LogSource.UserRepository, "Finished Updating User Repositry");
|
||||
await ReplyAsync(
|
||||
$"Successfully Populated User Repository with {success} Users in {_client.Guilds.Count} Guilds (Failed: {failed})");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context,
|
||||
"Couldn't complete User Repository, see console for more info");
|
||||
}
|
||||
}
|
||||
|
||||
[Command("refreshuser", RunMode = RunMode.Async)]
|
||||
[Summary("Refresh a user in the user cache")]
|
||||
public async Task PopUserRepoCommand([Summary("@someone")] IUser user)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _userRepository.Update(user as SocketUser);
|
||||
await ReplyAsync($"Refreshed: {user.Username}#{user.Discriminator}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("refreshuser", RunMode = RunMode.Async)]
|
||||
[Summary("Refresh a user in the user cache")]
|
||||
public async Task PopUserRepoCommand([Summary("user-id")] ulong userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = _client.GetUser(userId);
|
||||
await _userRepository.Update(user);
|
||||
await ReplyAsync($"Refreshed: {user.Username}#{user.Discriminator}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("error", RunMode = RunMode.Async)]
|
||||
[Summary("Throw an error un purpose")]
|
||||
public async Task PurposefulError()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new Exception("Error Generated by !owner error");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,197 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.Net;
|
||||
using Geekbot.Bot.CommandPreconditions;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Database.Models;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.Extensions;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
using Geekbot.Core.ReactionListener;
|
||||
using Localization = Geekbot.Core.Localization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Admin
|
||||
{
|
||||
[Group("role")]
|
||||
[DisableInDirectMessage]
|
||||
public class Role : GeekbotCommandBase
|
||||
{
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly IReactionListener _reactionListener;
|
||||
|
||||
public Role(DatabaseContext database, IErrorHandler errorHandler, IReactionListener reactionListener, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager)
|
||||
{
|
||||
_database = database;
|
||||
_reactionListener = reactionListener;
|
||||
}
|
||||
|
||||
[Command(RunMode = RunMode.Async)]
|
||||
[Summary("Get a list of all available roles.")]
|
||||
public async Task GetAllRoles()
|
||||
{
|
||||
try
|
||||
{
|
||||
var roles = _database.RoleSelfService.Where(g => g.GuildId.Equals(Context.Guild.Id.AsLong())).ToList();
|
||||
if (roles.Count == 0)
|
||||
{
|
||||
await ReplyAsync(Localization.Role.NoRolesConfigured);
|
||||
return;
|
||||
}
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine(string.Format(Localization.Role.ListHeader, Context.Guild.Name));
|
||||
sb.AppendLine(Localization.Role.ListInstruction);
|
||||
foreach (var role in roles) sb.AppendLine($"- {role.WhiteListName}");
|
||||
await ReplyAsync(sb.ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[Command(RunMode = RunMode.Async)]
|
||||
[Summary("Get a role by mentioning it.")]
|
||||
public async Task GiveRole([Summary("role-nickname")] string roleNameRaw)
|
||||
{
|
||||
try
|
||||
{
|
||||
var roleName = roleNameRaw.ToLower();
|
||||
var roleFromDb = _database.RoleSelfService.FirstOrDefault(e =>
|
||||
e.GuildId.Equals(Context.Guild.Id.AsLong()) && e.WhiteListName.Equals(roleName));
|
||||
if (roleFromDb != null)
|
||||
{
|
||||
var guildUser = (IGuildUser) Context.User;
|
||||
var role = Context.Guild.Roles.First(r => r.Id == roleFromDb.RoleId.AsUlong());
|
||||
if (role == null)
|
||||
{
|
||||
await ReplyAsync(Localization.Role.RoleNotFound);
|
||||
return;
|
||||
}
|
||||
|
||||
if (guildUser.RoleIds.Contains(role.Id))
|
||||
{
|
||||
await guildUser.RemoveRoleAsync(role);
|
||||
await ReplyAsync(string.Format(Localization.Role.RemovedUserFromRole, role.Name));
|
||||
return;
|
||||
}
|
||||
|
||||
await guildUser.AddRoleAsync(role);
|
||||
await ReplyAsync(string.Format(Localization.Role.AddedUserFromRole, role.Name));
|
||||
return;
|
||||
}
|
||||
|
||||
await ReplyAsync(Localization.Role.RoleNotFound);
|
||||
}
|
||||
catch (HttpException e)
|
||||
{
|
||||
if (e.HttpCode == HttpStatusCode.Forbidden)
|
||||
{
|
||||
await ReplyAsync(Localization.Internal.Http403);
|
||||
}
|
||||
else
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[RequireUserPermission(GuildPermission.ManageRoles)]
|
||||
[Command("add", RunMode = RunMode.Async)]
|
||||
[Summary("Add a role to the whitelist.")]
|
||||
public async Task AddRole([Summary("@role")] IRole role, [Summary("alias")] string roleName)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (role.IsManaged)
|
||||
{
|
||||
await ReplyAsync(Localization.Role.CannotAddManagedRole);
|
||||
return;
|
||||
}
|
||||
|
||||
if (role.Permissions.ManageRoles
|
||||
|| role.Permissions.Administrator
|
||||
|| role.Permissions.ManageGuild
|
||||
|| role.Permissions.BanMembers
|
||||
|| role.Permissions.KickMembers)
|
||||
{
|
||||
await ReplyAsync(Localization.Role.CannotAddDangerousRole);
|
||||
return;
|
||||
}
|
||||
|
||||
_database.RoleSelfService.Add(new RoleSelfServiceModel
|
||||
{
|
||||
GuildId = Context.Guild.Id.AsLong(),
|
||||
RoleId = role.Id.AsLong(),
|
||||
WhiteListName = roleName
|
||||
});
|
||||
await _database.SaveChangesAsync();
|
||||
await ReplyAsync(string.Format(Localization.Role.AddedRoleToWhitelist, role.Name));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[RequireUserPermission(GuildPermission.ManageRoles)]
|
||||
[Command("remove", RunMode = RunMode.Async)]
|
||||
[Summary("Remove a role from the whitelist.")]
|
||||
public async Task RemoveRole([Summary("role-nickname")] string roleName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var roleFromDb = _database.RoleSelfService.FirstOrDefault(e =>
|
||||
e.GuildId.Equals(Context.Guild.Id.AsLong()) && e.WhiteListName.Equals(roleName));
|
||||
if (roleFromDb != null)
|
||||
{
|
||||
_database.RoleSelfService.Remove(roleFromDb);
|
||||
await _database.SaveChangesAsync();
|
||||
await ReplyAsync(string.Format(Localization.Role.RemovedRoleFromWhitelist, roleName));
|
||||
return;
|
||||
}
|
||||
|
||||
await ReplyAsync(Localization.Role.RoleNotFound);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[RequireUserPermission(GuildPermission.ManageRoles)]
|
||||
[Summary("Give a role by clicking on an emoji")]
|
||||
[Command("listen", RunMode = RunMode.Async)]
|
||||
public async Task AddListener([Summary("message-ID")] string messageIdStr, [Summary("Emoji")] string emoji, [Summary("@role")] IRole role)
|
||||
{
|
||||
try
|
||||
{
|
||||
var messageId = ulong.Parse(messageIdStr);
|
||||
var message = (IUserMessage) await Context.Channel.GetMessageAsync(messageId);
|
||||
var emote = _reactionListener.ConvertStringToEmote(emoji);
|
||||
|
||||
await message.AddReactionAsync(emote);
|
||||
await _reactionListener.AddRoleToListener(messageId, Context.Guild.Id, emoji, role);
|
||||
await Context.Message.DeleteAsync();
|
||||
}
|
||||
catch (HttpException)
|
||||
{
|
||||
await Context.Channel.SendMessageAsync("Custom emojis from other servers are not supported");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.Extensions;
|
||||
using PokeAPI;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Games
|
||||
{
|
||||
public class Pokedex : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public Pokedex(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("pokedex", RunMode = RunMode.Async)]
|
||||
[Summary("A Pokedex Tool")]
|
||||
public async Task GetPokemon([Summary("pokemon-name")] string pokemonName)
|
||||
{
|
||||
try
|
||||
{
|
||||
DataFetcher.ShouldCacheData = true;
|
||||
Pokemon pokemon;
|
||||
try
|
||||
{
|
||||
pokemon = await DataFetcher.GetNamedApiObject<Pokemon>(pokemonName.ToLower());
|
||||
}
|
||||
catch
|
||||
{
|
||||
await ReplyAsync("I couldn't find that pokemon :confused:");
|
||||
return;
|
||||
}
|
||||
|
||||
var embed = await PokemonEmbedBuilder(pokemon);
|
||||
await ReplyAsync("", false, embed.Build());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<EmbedBuilder> PokemonEmbedBuilder(Pokemon pokemon)
|
||||
{
|
||||
var eb = new EmbedBuilder();
|
||||
var species = await DataFetcher.GetApiObject<PokemonSpecies>(pokemon.ID);
|
||||
eb.Title = $"#{pokemon.ID} {ToUpper(pokemon.Name)}";
|
||||
eb.Description = species.FlavorTexts[1].FlavorText;
|
||||
eb.ThumbnailUrl = pokemon.Sprites.FrontMale ?? pokemon.Sprites.FrontFemale;
|
||||
eb.AddInlineField(GetSingularOrPlural(pokemon.Types.Length, "Type"),
|
||||
string.Join(", ", pokemon.Types.Select(t => ToUpper(t.Type.Name))));
|
||||
eb.AddInlineField(GetSingularOrPlural(pokemon.Abilities.Length, "Ability"),
|
||||
string.Join(", ", pokemon.Abilities.Select(t => ToUpper(t.Ability.Name))));
|
||||
eb.AddInlineField("Height", pokemon.Height);
|
||||
eb.AddInlineField("Weight", pokemon.Mass);
|
||||
return eb;
|
||||
}
|
||||
|
||||
private string GetSingularOrPlural(int lenght, string word)
|
||||
{
|
||||
if (lenght == 1) return word;
|
||||
return word.EndsWith("y") ? $"{word.Remove(word.Length - 1)}ies" : $"{word}s";
|
||||
}
|
||||
|
||||
private string ToUpper(string s)
|
||||
{
|
||||
if (string.IsNullOrEmpty(s)) return string.Empty;
|
||||
return char.ToUpper(s[0]) + s.Substring(1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
using Geekbot.Core.KvInMemoryStore;
|
||||
using Geekbot.Core.RandomNumberGenerator;
|
||||
using Sentry;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Games.Roll
|
||||
{
|
||||
public class Roll : GeekbotCommandBase
|
||||
{
|
||||
private readonly IKvInMemoryStore _kvInMemoryStore;
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
||||
|
||||
public Roll(IKvInMemoryStore kvInMemoryStore, IErrorHandler errorHandler, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator, IGuildSettingsManager guildSettingsManager)
|
||||
: base(errorHandler, guildSettingsManager)
|
||||
{
|
||||
_kvInMemoryStore = kvInMemoryStore;
|
||||
_database = database;
|
||||
_randomNumberGenerator = randomNumberGenerator;
|
||||
}
|
||||
|
||||
[Command("roll", RunMode = RunMode.Async)]
|
||||
[Summary("Guess which number the bot will roll (1-100")]
|
||||
public async Task RollCommand([Remainder] [Summary("guess")] string stuff = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var res = await new Geekbot.Commands.Roll.Roll(_kvInMemoryStore, _database, _randomNumberGenerator)
|
||||
.RunFromGateway(
|
||||
Context.Guild.Id,
|
||||
Context.User.Id,
|
||||
Context.User.Username,
|
||||
stuff ?? "0"
|
||||
);
|
||||
await ReplyAsync(res);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
Transaction.Status = SpanStatus.InternalError;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Integrations.LolMmr
|
||||
{
|
||||
public class LolMmr : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public LolMmr(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("mmr", RunMode = RunMode.Async)]
|
||||
[Summary("Get the League of Legends MMR for a specified summoner")]
|
||||
public async Task GetMmr([Remainder] [Summary("summoner")] string summonerName)
|
||||
{
|
||||
try
|
||||
{
|
||||
LolMmrDto data;
|
||||
try
|
||||
{
|
||||
var name = HttpUtility.UrlEncode(summonerName.ToLower());
|
||||
var httpClient = HttpAbstractions.CreateDefaultClient();
|
||||
// setting the user agent in accordance with the whatismymmr.com api rules
|
||||
httpClient.DefaultRequestHeaders.Remove("User-Agent");
|
||||
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Linux:rocks.pizzaandcoffee.geekbot:v0.0.0");
|
||||
data = await HttpAbstractions.Get<LolMmrDto>(new Uri($"https://euw.whatismymmr.com/api/v1/summoner?name={name}"), httpClient);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
if (e.StatusCode != HttpStatusCode.NotFound) throw e;
|
||||
|
||||
await Context.Channel.SendMessageAsync("Player not found");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($"**MMR for {summonerName}**");
|
||||
sb.AppendLine($"Normal: {data.Normal?.Avg ?? 0}");
|
||||
sb.AppendLine($"Ranked: {data.Ranked?.Avg ?? 0}");
|
||||
sb.AppendLine($"ARAM: {data.ARAM?.Avg ?? 0}");
|
||||
|
||||
await Context.Channel.SendMessageAsync(sb.ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Integrations.LolMmr
|
||||
{
|
||||
public class LolMmrDto
|
||||
{
|
||||
[JsonPropertyName("ranked")]
|
||||
public LolMrrInfoDto Ranked { get; set; }
|
||||
|
||||
[JsonPropertyName("normal")]
|
||||
public LolMrrInfoDto Normal { get; set; }
|
||||
|
||||
[JsonPropertyName("aram")]
|
||||
public LolMrrInfoDto ARAM { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Integrations.LolMmr
|
||||
{
|
||||
public class LolMrrInfoDto
|
||||
{
|
||||
[JsonPropertyName("avg")]
|
||||
public decimal? Avg { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Converters;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.Extensions;
|
||||
using MtgApiManager.Lib.Service;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Integrations
|
||||
{
|
||||
public class MagicTheGathering : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
private readonly IMtgManaConverter _manaConverter;
|
||||
|
||||
public MagicTheGathering(IErrorHandler errorHandler, IMtgManaConverter manaConverter)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
_manaConverter = manaConverter;
|
||||
}
|
||||
|
||||
[Command("mtg", RunMode = RunMode.Async)]
|
||||
[Summary("Find a Magic The Gathering Card.")]
|
||||
public async Task GetCard([Remainder] [Summary("card-name")] string cardName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var message = await Context.Channel.SendMessageAsync($":mag: Looking up \"{cardName}\", please wait...");
|
||||
|
||||
var service = new CardService();
|
||||
var result = service
|
||||
.Where(x => x.Name, cardName)
|
||||
// fewer cards less risk of deserialization problems, don't need more than one anyways...
|
||||
.Where(x => x.PageSize, 1);
|
||||
|
||||
var cards = await result.AllAsync();
|
||||
if (!cards.IsSuccess)
|
||||
{
|
||||
await message.ModifyAsync(properties => properties.Content = $":warning: The Gatherer reacted in an unexpected way: {cards.Exception.Message}");
|
||||
return;
|
||||
}
|
||||
|
||||
var card = cards.Value.FirstOrDefault();
|
||||
|
||||
if (card == null)
|
||||
{
|
||||
await message.ModifyAsync(properties => properties.Content = ":red_circle: I couldn't find a card with that name...");
|
||||
return;
|
||||
}
|
||||
|
||||
var eb = new EmbedBuilder
|
||||
{
|
||||
Title = card.Name,
|
||||
Description = card.Type
|
||||
};
|
||||
|
||||
if (card.Colors != null) eb.WithColor(GetColor(card.Colors));
|
||||
|
||||
if (card.ImageUrl != null) eb.ImageUrl = card.ImageUrl.ToString();
|
||||
|
||||
if (!string.IsNullOrEmpty(card.Text)) eb.AddField("Text", _manaConverter.ConvertMana(card.Text));
|
||||
|
||||
if (!string.IsNullOrEmpty(card.Flavor)) eb.AddField("Flavor", card.Flavor);
|
||||
if (!string.IsNullOrEmpty(card.SetName)) eb.AddInlineField("Set", card.SetName);
|
||||
if (!string.IsNullOrEmpty(card.Power)) eb.AddInlineField("Power", card.Power);
|
||||
if (!string.IsNullOrEmpty(card.Loyalty)) eb.AddInlineField("Loyality", card.Loyalty);
|
||||
if (!string.IsNullOrEmpty(card.Toughness)) eb.AddInlineField("Thoughness", card.Toughness);
|
||||
|
||||
if (!string.IsNullOrEmpty(card.ManaCost)) eb.AddInlineField("Cost", _manaConverter.ConvertMana(card.ManaCost));
|
||||
if (!string.IsNullOrEmpty(card.Rarity)) eb.AddInlineField("Rarity", card.Rarity);
|
||||
|
||||
if (card.Legalities != null && card.Legalities.Count > 0)
|
||||
eb.AddField("Legality", string.Join(", ", card.Legalities.Select(e => e.Format)));
|
||||
|
||||
await message.ModifyAsync(properties =>
|
||||
{
|
||||
properties.Content = string.Empty;
|
||||
properties.Embed = eb.Build();
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
private Color GetColor(IEnumerable<string> colors)
|
||||
{
|
||||
var color = colors.FirstOrDefault();
|
||||
return color switch
|
||||
{
|
||||
"Black" => new Color(203, 194, 191),
|
||||
"White" => new Color(255, 251, 213),
|
||||
"Blue" => new Color(170, 224, 250),
|
||||
"Red" => new Color(250, 170, 143),
|
||||
"Green" => new Color(155, 211, 174),
|
||||
_ => new Color(204, 194, 212)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.Extensions;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
using JikanDotNet;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Integrations
|
||||
{
|
||||
public class Mal : GeekbotCommandBase
|
||||
{
|
||||
private readonly IJikan _client;
|
||||
|
||||
public Mal(IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager)
|
||||
{
|
||||
_client = new Jikan();
|
||||
}
|
||||
|
||||
[Command("anime", RunMode = RunMode.Async)]
|
||||
[Summary("Show Info about an Anime.")]
|
||||
public async Task SearchAnime([Remainder] [Summary("anime-name")] string animeName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var results = await _client.SearchAnime(animeName);
|
||||
var anime = results.Results.FirstOrDefault();
|
||||
if (anime != null)
|
||||
{
|
||||
var eb = new EmbedBuilder
|
||||
{
|
||||
Title = anime.Title,
|
||||
Description = anime.Description,
|
||||
ImageUrl = anime.ImageURL
|
||||
};
|
||||
|
||||
eb.AddInlineField("Premiere", FormatDate(anime.StartDate))
|
||||
.AddInlineField("Ended", anime.Airing ? "-" : FormatDate(anime.EndDate))
|
||||
.AddInlineField("Episodes", anime.Episodes)
|
||||
.AddInlineField("MAL Score", anime.Score)
|
||||
.AddInlineField("Type", anime.Type)
|
||||
.AddField("MAL Link", $"https://myanimelist.net/anime/{anime.MalId}");
|
||||
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyAsync("No anime found with that name...");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("manga", RunMode = RunMode.Async)]
|
||||
[Summary("Show Info about a Manga.")]
|
||||
public async Task SearchManga([Remainder] [Summary("manga-name")] string mangaName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var results = await _client.SearchManga(mangaName);
|
||||
var manga = results.Results.FirstOrDefault();
|
||||
if (manga != null)
|
||||
{
|
||||
var eb = new EmbedBuilder
|
||||
{
|
||||
Title = manga.Title,
|
||||
Description = manga.Description,
|
||||
ImageUrl = manga.ImageURL
|
||||
};
|
||||
|
||||
eb.AddInlineField("Premiere", FormatDate(manga.StartDate))
|
||||
.AddInlineField("Ended", manga.Publishing ? "-" : FormatDate(manga.EndDate))
|
||||
.AddInlineField("Volumes", manga.Volumes)
|
||||
.AddInlineField("Chapters", manga.Chapters)
|
||||
.AddInlineField("MAL Score", manga.Score)
|
||||
.AddField("MAL Link", $"https://myanimelist.net/manga/{manga.MalId}");
|
||||
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyAsync("No manga found with that name...");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
private string FormatDate(DateTime? dateTime)
|
||||
{
|
||||
if (!dateTime.HasValue)
|
||||
{
|
||||
return DateTime.MinValue.ToString("d", Thread.CurrentThread.CurrentUICulture);
|
||||
}
|
||||
|
||||
return dateTime.Value.ToString("d", Thread.CurrentThread.CurrentUICulture);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Integrations
|
||||
{
|
||||
public class UrbanDictionary : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public UrbanDictionary(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("urban", RunMode = RunMode.Async)]
|
||||
[Summary("Lookup something on urban dictionary")]
|
||||
public async Task UrbanDefine([Remainder] [Summary("word")] string word)
|
||||
{
|
||||
try
|
||||
{
|
||||
var eb = await Geekbot.Commands.UrbanDictionary.UrbanDictionary.Run(word);
|
||||
if (eb == null)
|
||||
{
|
||||
await ReplyAsync("That word hasn't been defined...");
|
||||
return;
|
||||
}
|
||||
|
||||
await ReplyAsync(string.Empty, false, eb.ToDiscordNetEmbed().Build());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.Extensions;
|
||||
using Geekbot.Core.WikipediaClient;
|
||||
using Geekbot.Core.WikipediaClient.Page;
|
||||
using HtmlAgilityPack;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Integrations
|
||||
{
|
||||
public class Wikipedia : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
private readonly IWikipediaClient _wikipediaClient;
|
||||
private readonly DatabaseContext _database;
|
||||
|
||||
public Wikipedia(IErrorHandler errorHandler, IWikipediaClient wikipediaClient, DatabaseContext database)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
_wikipediaClient = wikipediaClient;
|
||||
_database = database;
|
||||
}
|
||||
|
||||
[Command("wiki", RunMode = RunMode.Async)]
|
||||
[Summary("Get an article from wikipedia.")]
|
||||
public async Task GetPreview([Remainder] [Summary("article")] string articleName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var wikiLang = _database.GuildSettings.FirstOrDefault(g => g.GuildId.Equals(Context.Guild.Id.AsLong()))?.WikiLang;
|
||||
if (string.IsNullOrEmpty(wikiLang))
|
||||
{
|
||||
wikiLang = "en";
|
||||
}
|
||||
var article = await _wikipediaClient.GetPreview(articleName.Replace(" ", "_"), wikiLang);
|
||||
|
||||
if (article.Type != PageTypes.Standard)
|
||||
{
|
||||
switch (article.Type)
|
||||
{
|
||||
case PageTypes.Disambiguation:
|
||||
await ReplyAsync($"**__Disambiguation__**\r\n{DisambiguationExtractor(article.ExtractHtml)}");
|
||||
break;
|
||||
case PageTypes.MainPage:
|
||||
await ReplyAsync("The main page is not supported");
|
||||
break;
|
||||
case PageTypes.NoExtract:
|
||||
await ReplyAsync($"This page has no summary, here is the link: {article.ContentUrls.Desktop.Page}");
|
||||
break;
|
||||
case PageTypes.Standard:
|
||||
break;
|
||||
default:
|
||||
await ReplyAsync($"This page type is currently not supported, here is the link: {article.ContentUrls.Desktop.Page}");
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var eb = new EmbedBuilder
|
||||
{
|
||||
Title = article.Title,
|
||||
Description = article.Description,
|
||||
ImageUrl = article.Thumbnail?.Source.ToString(),
|
||||
Url = article.ContentUrls.Desktop.Page.ToString(),
|
||||
Color = new Color(246,246,246),
|
||||
Timestamp = article.Timestamp,
|
||||
Footer = new EmbedFooterBuilder
|
||||
{
|
||||
Text = "Last Edit",
|
||||
IconUrl = "http://icons.iconarchive.com/icons/sykonist/popular-sites/256/Wikipedia-icon.png"
|
||||
}
|
||||
};
|
||||
|
||||
eb.AddField("Description", article.Extract);
|
||||
if (article.Coordinates != null) eb.AddField("Coordinates", $"{article.Coordinates.Lat} Lat {article.Coordinates.Lon} Lon");
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
await ReplyAsync("I couldn't find that article");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
private string DisambiguationExtractor(string extractHtml)
|
||||
{
|
||||
var doc = new HtmlDocument();
|
||||
doc.LoadHtml(extractHtml);
|
||||
var nodes = doc.DocumentNode.SelectNodes("//li");
|
||||
if (nodes == null) return "(List is to long to show)";
|
||||
var sb = new StringBuilder();
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
var split = node.InnerText.Split(',');
|
||||
var title = split.First();
|
||||
var desc = string.Join(",", split.Skip(1));
|
||||
sb.AppendLine($"• **{title}** -{desc}");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
// using Geekbot.Core.ErrorHandling;
|
||||
// using Geekbot.Core.GlobalSettings;
|
||||
// using Google.Apis.Services;
|
||||
// using Google.Apis.YouTube.v3;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Integrations
|
||||
{
|
||||
public class Youtube : TransactionModuleBase
|
||||
{
|
||||
// private readonly IGlobalSettings _globalSettings;
|
||||
// private readonly IErrorHandler _errorHandler;
|
||||
|
||||
// public Youtube(IGlobalSettings globalSettings, IErrorHandler errorHandler)
|
||||
// {
|
||||
// _globalSettings = globalSettings;
|
||||
// _errorHandler = errorHandler;
|
||||
// }
|
||||
|
||||
[Command("yt", RunMode = RunMode.Async)]
|
||||
[Summary("Search for something on youtube.")]
|
||||
public async Task Yt([Remainder] [Summary("title")] string searchQuery)
|
||||
{
|
||||
await ReplyAsync("The youtube command is temporarily disabled");
|
||||
|
||||
// var key = _globalSettings.GetKey("YoutubeKey");
|
||||
// if (string.IsNullOrEmpty(key))
|
||||
// {
|
||||
// await ReplyAsync("No youtube key set, please tell my senpai to set one");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// var youtubeService = new YouTubeService(new BaseClientService.Initializer
|
||||
// {
|
||||
// ApiKey = key,
|
||||
// ApplicationName = GetType().ToString()
|
||||
// });
|
||||
//
|
||||
// var searchListRequest = youtubeService.Search.List("snippet");
|
||||
// searchListRequest.Q = searchQuery;
|
||||
// searchListRequest.MaxResults = 2;
|
||||
//
|
||||
// var searchListResponse = await searchListRequest.ExecuteAsync();
|
||||
//
|
||||
// var result = searchListResponse.Items[0];
|
||||
//
|
||||
// await ReplyAsync(
|
||||
// $"\"{result.Snippet.Title}\" from \"{result.Snippet.ChannelTitle}\" https://youtu.be/{result.Id.VideoId}");
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// await _errorHandler.HandleCommandException(e, Context);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.RandomNumberGenerator;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Randomness
|
||||
{
|
||||
public class BenedictCumberbatchNameGenerator : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
||||
|
||||
public BenedictCumberbatchNameGenerator(IErrorHandler errorHandler, IRandomNumberGenerator randomNumberGenerator)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
_randomNumberGenerator = randomNumberGenerator;
|
||||
}
|
||||
|
||||
[Command("bdcb", RunMode = RunMode.Async)]
|
||||
[Summary("Benedict Cumberbatch Name Generator")]
|
||||
public async Task GetQuote()
|
||||
{
|
||||
try
|
||||
{
|
||||
var firstnameList = new List<string>
|
||||
{
|
||||
"Bumblebee", "Bandersnatch", "Broccoli", "Rinkydink", "Bombadil", "Boilerdang", "Bandicoot", "Fragglerock", "Muffintop", "Congleton", "Blubberdick", "Buffalo", "Benadryl",
|
||||
"Butterfree", "Burberry", "Whippersnatch", "Buttermilk", "Beezlebub", "Budapest", "Boilerdang", "Blubberwhale", "Bumberstump", "Bulbasaur", "Cogglesnatch", "Liverswort",
|
||||
"Bodybuild", "Johnnycash", "Bendydick", "Burgerking", "Bonaparte", "Bunsenburner", "Billiardball", "Bukkake", "Baseballmitt", "Blubberbutt", "Baseballbat", "Rumblesack",
|
||||
"Barister", "Danglerack", "Rinkydink", "Bombadil", "Honkytonk", "Billyray", "Bumbleshack", "Snorkeldink", "Beetlejuice", "Bedlington", "Bandicoot", "Boobytrap", "Blenderdick",
|
||||
"Bentobox", "Pallettown", "Wimbledon", "Buttercup", "Blasphemy", "Syphilis", "Snorkeldink", "Brandenburg", "Barbituate", "Snozzlebert", "Tiddleywomp", "Bouillabaisse",
|
||||
"Wellington", "Benetton", "Bendandsnap", "Timothy", "Brewery", "Bentobox", "Brandybuck", "Benjamin", "Buckminster", "Bourgeoisie", "Bakery", "Oscarbait", "Buckyball",
|
||||
"Bourgeoisie", "Burlington", "Buckingham", "Barnoldswick", "Bumblesniff", "Butercup", "Bubblebath", "Fiddlestick", "Bulbasaur", "Bumblebee", "Bettyboop", "Botany", "Cadbury",
|
||||
"Brendadirk", "Buckingham", "Barnabus", "Barnacle", "Billybong", "Botany", "Benddadick", "Benderchick"
|
||||
};
|
||||
|
||||
var lastnameList = new List<string>
|
||||
{
|
||||
"Coddleswort", "Crumplesack", "Curdlesnoot", "Calldispatch", "Humperdinck", "Rivendell", "Cuttlefish", "Lingerie", "Vegemite", "Ampersand", "Cumberbund", "Candycrush",
|
||||
"Clombyclomp", "Cragglethatch", "Nottinghill", "Cabbagepatch", "Camouflage", "Creamsicle", "Curdlemilk", "Upperclass", "Frumblesnatch", "Crumplehorn", "Talisman", "Candlestick",
|
||||
"Chesterfield", "Bumbersplat", "Scratchnsniff", "Snugglesnatch", "Charizard", "Carrotstick", "Cumbercooch", "Crackerjack", "Crucifix", "Cuckatoo", "Cockletit", "Collywog",
|
||||
"Capncrunch", "Covergirl", "Cumbersnatch", "Countryside", "Coggleswort", "Splishnsplash", "Copperwire", "Animorph", "Curdledmilk", "Cheddarcheese", "Cottagecheese", "Crumplehorn",
|
||||
"Snickersbar", "Banglesnatch", "Stinkyrash", "Cameltoe", "Chickenbroth", "Concubine", "Candygram", "Moldyspore", "Chuckecheese", "Cankersore", "Crimpysnitch", "Wafflesmack",
|
||||
"Chowderpants", "Toodlesnoot", "Clavichord", "Cuckooclock", "Oxfordshire", "Cumbersome", "Chickenstrips", "Battleship", "Commonwealth", "Cunningsnatch", "Custardbath",
|
||||
"Kryptonite", "Curdlesnoot", "Cummerbund", "Coochyrash", "Crackerdong", "Crackerdong", "Curdledong", "Crackersprout", "Crumplebutt", "Colonist", "Coochierash", "Anglerfish",
|
||||
"Cumbersniff", "Charmander", "Scratch-n-sniff", "Cumberbitch", "Pumpkinpatch", "Cramplesnutch", "Lumberjack", "Bonaparte", "Cul-de-sac", "Cankersore", "Cucumbercatch", "Contradict"
|
||||
};
|
||||
|
||||
var lastname = lastnameList[_randomNumberGenerator.Next(0, lastnameList.Count - 1)];
|
||||
var firstname = firstnameList[_randomNumberGenerator.Next(0, firstnameList.Count - 1)];
|
||||
|
||||
await ReplyAsync($"{firstname} {lastname}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Randomness.Cat
|
||||
{
|
||||
public class Cat : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public Cat(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("cat", RunMode = RunMode.Async)]
|
||||
[Summary("Return a random image of a cat.")]
|
||||
public async Task Say()
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await HttpAbstractions.Get<CatResponseDto>(new Uri("https://aws.random.cat/meow"));
|
||||
var eb = new EmbedBuilder
|
||||
{
|
||||
ImageUrl = response.File
|
||||
};
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Randomness.Cat
|
||||
{
|
||||
internal class CatResponseDto
|
||||
{
|
||||
[JsonPropertyName("file")]
|
||||
public string File { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Randomness.Chuck
|
||||
{
|
||||
internal class ChuckNorrisJokeResponseDto
|
||||
{
|
||||
[JsonPropertyName("value")]
|
||||
public string Value { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Randomness.Chuck
|
||||
{
|
||||
public class ChuckNorrisJokes : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public ChuckNorrisJokes(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("chuck", RunMode = RunMode.Async)]
|
||||
[Summary("A random chuck norris joke")]
|
||||
public async Task Say()
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await HttpAbstractions.Get<ChuckNorrisJokeResponseDto>(new Uri("https://api.chucknorris.io/jokes/random"));
|
||||
await ReplyAsync(response.Value);
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
await ReplyAsync("Api down...");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Randomness.Dad
|
||||
{
|
||||
internal class DadJokeResponseDto
|
||||
{
|
||||
[JsonPropertyName("joke")]
|
||||
public string Joke { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Randomness.Dad
|
||||
{
|
||||
public class DadJokes : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public DadJokes(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("dad", RunMode = RunMode.Async)]
|
||||
[Summary("A random dad joke")]
|
||||
public async Task Say()
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await HttpAbstractions.Get<DadJokeResponseDto>(new Uri("https://icanhazdadjoke.com/"));
|
||||
await ReplyAsync(response.Joke);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Randomness.Dog
|
||||
{
|
||||
public class Dog : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public Dog(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("dog", RunMode = RunMode.Async)]
|
||||
[Summary("Return a random image of a dog.")]
|
||||
public async Task Say()
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await HttpAbstractions.Get<DogResponseDto>(new Uri("http://random.dog/woof.json"));
|
||||
await ReplyAsync(response.Url);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Randomness.Dog
|
||||
{
|
||||
internal class DogResponseDto
|
||||
{
|
||||
[JsonPropertyName("url")]
|
||||
public string Url { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
using Localization = Geekbot.Core.Localization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Randomness
|
||||
{
|
||||
public class EightBall : GeekbotCommandBase
|
||||
{
|
||||
public EightBall(IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager)
|
||||
{
|
||||
}
|
||||
|
||||
[Command("8ball", RunMode = RunMode.Async)]
|
||||
[Summary("Ask 8Ball a Question.")]
|
||||
public async Task Ball([Remainder] [Summary("question")] string echo)
|
||||
{
|
||||
try
|
||||
{
|
||||
var enumerator = Localization.EightBall.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true).GetEnumerator();
|
||||
var replies = new List<string>();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
replies.Add(enumerator.Value?.ToString());
|
||||
}
|
||||
|
||||
var answer = new Random().Next(replies.Count);
|
||||
await ReplyAsync(replies[answer]);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Media;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Randomness
|
||||
{
|
||||
public class Fortune : TransactionModuleBase
|
||||
{
|
||||
private readonly IFortunesProvider _fortunes;
|
||||
|
||||
public Fortune(IFortunesProvider fortunes)
|
||||
{
|
||||
_fortunes = fortunes;
|
||||
}
|
||||
|
||||
[Command("fortune", RunMode = RunMode.Async)]
|
||||
[Summary("Get a random fortune")]
|
||||
public async Task GetAFortune()
|
||||
{
|
||||
await ReplyAsync(_fortunes.GetRandomFortune());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Randomness.Kanye
|
||||
{
|
||||
public class Kanye : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public Kanye(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("kanye", RunMode = RunMode.Async)]
|
||||
[Summary("A random kayne west quote")]
|
||||
public async Task Say()
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await HttpAbstractions.Get<KanyeResponseDto>(new Uri("https://api.kanye.rest/"));
|
||||
await ReplyAsync(response.Quote);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Randomness.Kanye
|
||||
{
|
||||
public class KanyeResponseDto
|
||||
{
|
||||
[JsonPropertyName("quote")]
|
||||
public string Quote { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Media;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Randomness
|
||||
{
|
||||
public class RandomAnimals : TransactionModuleBase
|
||||
{
|
||||
private readonly IMediaProvider _mediaProvider;
|
||||
|
||||
public RandomAnimals(IMediaProvider mediaProvider)
|
||||
{
|
||||
_mediaProvider = mediaProvider;
|
||||
}
|
||||
|
||||
[Command("panda", RunMode = RunMode.Async)]
|
||||
[Summary("Get a random panda image")]
|
||||
public async Task Panda()
|
||||
{
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Panda)));
|
||||
}
|
||||
|
||||
[Command("croissant", RunMode = RunMode.Async)]
|
||||
[Alias("gipfeli")]
|
||||
[Summary("Get a random croissant image")]
|
||||
public async Task Croissant()
|
||||
{
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Croissant)));
|
||||
}
|
||||
|
||||
[Command("pumpkin", RunMode = RunMode.Async)]
|
||||
[Summary("Get a random pumpkin image")]
|
||||
public async Task Pumpkin()
|
||||
{
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Pumpkin)));
|
||||
}
|
||||
|
||||
[Command("squirrel", RunMode = RunMode.Async)]
|
||||
[Summary("Get a random squirrel image")]
|
||||
public async Task Squirrel()
|
||||
{
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Squirrel)));
|
||||
}
|
||||
|
||||
[Command("turtle", RunMode = RunMode.Async)]
|
||||
[Summary("Get a random turtle image")]
|
||||
public async Task Turtle()
|
||||
{
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Turtle)));
|
||||
}
|
||||
|
||||
[Command("penguin", RunMode = RunMode.Async)]
|
||||
[Alias("pengu")]
|
||||
[Summary("Get a random penguin image")]
|
||||
public async Task Penguin()
|
||||
{
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Penguin)));
|
||||
}
|
||||
|
||||
[Command("fox", RunMode = RunMode.Async)]
|
||||
[Summary("Get a random fox image")]
|
||||
public async Task Fox()
|
||||
{
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Fox)));
|
||||
}
|
||||
|
||||
[Command("dab", RunMode = RunMode.Async)]
|
||||
[Summary("Get a random dab image")]
|
||||
public async Task Dab()
|
||||
{
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Dab)));
|
||||
}
|
||||
|
||||
private static Embed Eb(string image)
|
||||
{
|
||||
return new EmbedBuilder {ImageUrl = image}.Build();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Database.Models;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.Extensions;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
using Geekbot.Core.RandomNumberGenerator;
|
||||
using Localization = Geekbot.Core.Localization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Randomness
|
||||
{
|
||||
public class Ship : GeekbotCommandBase
|
||||
{
|
||||
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
||||
private readonly DatabaseContext _database;
|
||||
|
||||
public Ship(DatabaseContext database, IErrorHandler errorHandler, IRandomNumberGenerator randomNumberGenerator, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager)
|
||||
{
|
||||
_database = database;
|
||||
_randomNumberGenerator = randomNumberGenerator;
|
||||
}
|
||||
|
||||
[Command("Ship", RunMode = RunMode.Async)]
|
||||
[Summary("Ask the Shipping meter")]
|
||||
public async Task Command([Summary("@user1")] IUser user1, [Summary("@user2")] IUser user2)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userKeys = user1.Id < user2.Id
|
||||
? new Tuple<long, long>(user1.Id.AsLong(), user2.Id.AsLong())
|
||||
: new Tuple<long, long>(user2.Id.AsLong(), user1.Id.AsLong());
|
||||
|
||||
var dbval = _database.Ships.FirstOrDefault(s =>
|
||||
s.FirstUserId.Equals(userKeys.Item1) &&
|
||||
s.SecondUserId.Equals(userKeys.Item2));
|
||||
|
||||
var shippingRate = 0;
|
||||
if (dbval == null)
|
||||
{
|
||||
shippingRate = _randomNumberGenerator.Next(1, 100);
|
||||
_database.Ships.Add(new ShipsModel()
|
||||
{
|
||||
FirstUserId = userKeys.Item1,
|
||||
SecondUserId = userKeys.Item2,
|
||||
Strength = shippingRate
|
||||
});
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
shippingRate = dbval.Strength;
|
||||
}
|
||||
|
||||
var reply = $":heartpulse: **{Localization.Ship.Matchmaking}** :heartpulse:\r\n";
|
||||
reply += $":two_hearts: {user1.Mention} :heart: {user2.Mention} :two_hearts:\r\n";
|
||||
reply += $"0% [{BlockCounter(shippingRate)}] 100% - {DeterminateSuccess(shippingRate)}";
|
||||
await ReplyAsync(reply);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
private string DeterminateSuccess(int rate)
|
||||
{
|
||||
return (rate / 20) switch
|
||||
{
|
||||
0 => Localization.Ship.NotGoingToHappen,
|
||||
1 => Localization.Ship.NotSuchAGoodIdea,
|
||||
2 => Localization.Ship.ThereMightBeAChance,
|
||||
3 => Localization.Ship.CouldWork,
|
||||
4 => Localization.Ship.ItsAMatch,
|
||||
_ => "nope"
|
||||
};
|
||||
}
|
||||
|
||||
private string BlockCounter(int rate)
|
||||
{
|
||||
var amount = rate / 10;
|
||||
Console.WriteLine(amount);
|
||||
var blocks = "";
|
||||
for (var i = 1; i <= 10; i++)
|
||||
if (i <= amount)
|
||||
{
|
||||
blocks += ":white_medium_small_square:";
|
||||
if (i == amount)
|
||||
blocks += $" {rate}% ";
|
||||
}
|
||||
else
|
||||
{
|
||||
blocks += ":black_medium_small_square:";
|
||||
}
|
||||
|
||||
return blocks;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Database.Models;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.Extensions;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Randomness
|
||||
{
|
||||
public class Slap : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
private readonly DatabaseContext _database;
|
||||
|
||||
public Slap(IErrorHandler errorHandler, DatabaseContext database)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
_database = database;
|
||||
}
|
||||
|
||||
[Command("slap", RunMode = RunMode.Async)]
|
||||
[Summary("slap someone")]
|
||||
public async Task Slapper([Summary("@someone")] IUser user)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (user.Id == Context.User.Id)
|
||||
{
|
||||
await ReplyAsync("Why would you slap yourself?");
|
||||
return;
|
||||
}
|
||||
|
||||
var things = new List<string>
|
||||
{
|
||||
"thing",
|
||||
"rubber chicken",
|
||||
"leek stick",
|
||||
"large trout",
|
||||
"flat hand",
|
||||
"strip of bacon",
|
||||
"feather",
|
||||
"piece of pizza",
|
||||
"moldy banana",
|
||||
"sharp retort",
|
||||
"printed version of wikipedia",
|
||||
"panda paw",
|
||||
"spiked sledgehammer",
|
||||
"monstertruck",
|
||||
"dirty toilet brush",
|
||||
"sleeping seagull",
|
||||
"sunflower",
|
||||
"mousepad",
|
||||
"lolipop",
|
||||
"bottle of rum",
|
||||
"cheese slice",
|
||||
"critical 1",
|
||||
"natural 20",
|
||||
"mjölnir (aka mewmew)",
|
||||
"kamehameha",
|
||||
"copy of Twilight",
|
||||
"med pack (get ready for the end boss)",
|
||||
"derp",
|
||||
"condom (used)",
|
||||
"gremlin fed after midnight",
|
||||
"wet baguette",
|
||||
"exploding kitten",
|
||||
"shiny piece of shit",
|
||||
"mismatched pair of socks",
|
||||
"horcrux",
|
||||
"tuna",
|
||||
"suggestion",
|
||||
"teapot",
|
||||
"candle",
|
||||
"dictionary",
|
||||
"powerless banhammer",
|
||||
"piece of low fat mozzarella",
|
||||
// For some reason it never picks the last one
|
||||
// Adding this workaround, because i'm to lazy to actually fix it at the time of writing this
|
||||
"padding"
|
||||
};
|
||||
|
||||
await ReplyAsync($"{Context.User.Username} slapped {user.Username} with a {things[new Random().Next(0, things.Count - 1)]}");
|
||||
|
||||
await UpdateRecieved(user.Id);
|
||||
await UpdateGiven(Context.User.Id);
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateGiven(ulong userId)
|
||||
{
|
||||
var user = await GetUser(userId);
|
||||
user.Given++;
|
||||
_database.Slaps.Update(user);
|
||||
}
|
||||
|
||||
private async Task UpdateRecieved(ulong userId)
|
||||
{
|
||||
var user = await GetUser(userId);
|
||||
user.Recieved++;
|
||||
_database.Slaps.Update(user);
|
||||
}
|
||||
|
||||
private async Task<SlapsModel> GetUser(ulong userId)
|
||||
{
|
||||
var user = _database.Slaps.FirstOrDefault(e =>
|
||||
e.GuildId.Equals(Context.Guild.Id.AsLong()) &&
|
||||
e.UserId.Equals(userId.AsLong())
|
||||
);
|
||||
|
||||
if (user != null) return user;
|
||||
|
||||
_database.Slaps.Add(new SlapsModel
|
||||
{
|
||||
GuildId = Context.Guild.Id.AsLong(),
|
||||
UserId = userId.AsLong(),
|
||||
Recieved = 0,
|
||||
Given = 0
|
||||
});
|
||||
await _database.SaveChangesAsync();
|
||||
return _database.Slaps.FirstOrDefault(e =>
|
||||
e.GuildId.Equals(Context.Guild.Id.AsLong()) &&
|
||||
e.UserId.Equals(userId.AsLong()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,164 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Bot.CommandPreconditions;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Database.Models;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.Extensions;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
using Geekbot.Core.RandomNumberGenerator;
|
||||
using Localization = Geekbot.Core.Localization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Rpg
|
||||
{
|
||||
[DisableInDirectMessage]
|
||||
[Group("cookies")]
|
||||
[Alias("cookie")]
|
||||
public class Cookies : GeekbotCommandBase
|
||||
{
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
||||
|
||||
public Cookies(DatabaseContext database, IErrorHandler errorHandler, IRandomNumberGenerator randomNumberGenerator, IGuildSettingsManager guildSettingsManager)
|
||||
: base(errorHandler, guildSettingsManager)
|
||||
{
|
||||
_database = database;
|
||||
_randomNumberGenerator = randomNumberGenerator;
|
||||
}
|
||||
|
||||
[Command("get", RunMode = RunMode.Async)]
|
||||
[Summary("Get a cookie every 24 hours")]
|
||||
public async Task GetCookies()
|
||||
{
|
||||
try
|
||||
{
|
||||
var actor = await GetUser(Context.User.Id);
|
||||
var timeoutDays = 1;
|
||||
if (actor.LastPayout?.AddDays(timeoutDays) > DateTime.Now.ToUniversalTime())
|
||||
{
|
||||
var remaining = actor.LastPayout.Value.AddDays(timeoutDays) - DateTimeOffset.Now.ToUniversalTime();
|
||||
var formattedWaitTime = DateLocalization.FormatDateTimeAsRemaining(remaining);
|
||||
await ReplyAsync(string.Format(Localization.Cookies.WaitForMoreCookies, formattedWaitTime));
|
||||
return;
|
||||
}
|
||||
actor.Cookies += 10;
|
||||
actor.LastPayout = DateTimeOffset.Now.ToUniversalTime();
|
||||
await SetUser(actor);
|
||||
await ReplyAsync(string.Format(Localization.Cookies.GetCookies, 10, actor.Cookies));
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("jar", RunMode = RunMode.Async)]
|
||||
[Summary("Look at your cookie jar")]
|
||||
public async Task PeekIntoCookieJar()
|
||||
{
|
||||
try
|
||||
{
|
||||
var actor = await GetUser(Context.User.Id);
|
||||
await ReplyAsync(string.Format(Localization.Cookies.InYourJar, actor.Cookies));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("give", RunMode = RunMode.Async)]
|
||||
[Summary("Give cookies to someone")]
|
||||
public async Task GiveACookie([Summary("@someone")] IUser user, [Summary("amount")] int amount = 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
var giver = await GetUser(Context.User.Id);
|
||||
|
||||
if (amount < 1)
|
||||
{
|
||||
await ReplyAsync(Localization.Cookies.CantTakeCookies);
|
||||
return;
|
||||
}
|
||||
|
||||
if (giver.Cookies < amount)
|
||||
{
|
||||
await ReplyAsync(Localization.Cookies.NotEnoughToGive);
|
||||
return;
|
||||
}
|
||||
|
||||
var taker = await GetUser(user.Id);
|
||||
|
||||
giver.Cookies -= amount;
|
||||
taker.Cookies += amount;
|
||||
|
||||
await SetUser(giver);
|
||||
await SetUser(taker);
|
||||
|
||||
await ReplyAsync(string.Format(Localization.Cookies.Given, amount, user.Username));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("eat", RunMode = RunMode.Async)]
|
||||
[Summary("Eat a cookie")]
|
||||
public async Task EatACookie()
|
||||
{
|
||||
try
|
||||
{
|
||||
var actor = await GetUser(Context.User.Id);
|
||||
|
||||
if (actor.Cookies < 5)
|
||||
{
|
||||
await ReplyAsync(Localization.Cookies.NotEnoughCookiesToEat);
|
||||
return;
|
||||
}
|
||||
|
||||
var amount = _randomNumberGenerator.Next(1, 5);
|
||||
actor.Cookies -= amount;
|
||||
|
||||
await SetUser(actor);
|
||||
|
||||
await ReplyAsync(string.Format(Localization.Cookies.AteCookies, amount, actor.Cookies));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<CookiesModel> GetUser(ulong userId)
|
||||
{
|
||||
var user = _database.Cookies.FirstOrDefault(u =>u.GuildId.Equals(Context.Guild.Id.AsLong()) && u.UserId.Equals(userId.AsLong())) ?? await CreateNewRow(userId);
|
||||
return user;
|
||||
}
|
||||
|
||||
private async Task SetUser(CookiesModel user)
|
||||
{
|
||||
_database.Cookies.Update(user);
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private async Task<CookiesModel> CreateNewRow(ulong userId)
|
||||
{
|
||||
var user = new CookiesModel()
|
||||
{
|
||||
GuildId = Context.Guild.Id.AsLong(),
|
||||
UserId = userId.AsLong(),
|
||||
Cookies = 0,
|
||||
LastPayout = DateTimeOffset.MinValue.ToUniversalTime()
|
||||
};
|
||||
var newUser = _database.Cookies.Add(user).Entity;
|
||||
await _database.SaveChangesAsync();
|
||||
return newUser;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Bot.CommandPreconditions;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.Extensions;
|
||||
using Geekbot.Core.Levels;
|
||||
|
||||
namespace Geekbot.Bot.Commands.User
|
||||
{
|
||||
public class GuildInfo : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly ILevelCalc _levelCalc;
|
||||
|
||||
public GuildInfo(DatabaseContext database, ILevelCalc levelCalc, IErrorHandler errorHandler)
|
||||
{
|
||||
_database = database;
|
||||
_levelCalc = levelCalc;
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("serverstats", RunMode = RunMode.Async)]
|
||||
[Summary("Show some info about the bot.")]
|
||||
[DisableInDirectMessage]
|
||||
public async Task GetInfo()
|
||||
{
|
||||
try
|
||||
{
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithAuthor(new EmbedAuthorBuilder()
|
||||
.WithIconUrl(Context.Guild.IconUrl)
|
||||
.WithName(Context.Guild.Name));
|
||||
eb.WithColor(new Color(110, 204, 147));
|
||||
|
||||
var created = Context.Guild.CreatedAt;
|
||||
var age = Math.Floor((DateTime.Now - created).TotalDays);
|
||||
|
||||
var messages = _database.Messages
|
||||
.Where(e => e.GuildId == Context.Guild.Id.AsLong())
|
||||
.Sum(e => e.MessageCount);
|
||||
var level = _levelCalc.GetLevel(messages);
|
||||
|
||||
eb.AddField("Server Age", $"{created.Day}/{created.Month}/{created.Year} ({age} days)");
|
||||
eb.AddInlineField("Level", level)
|
||||
.AddInlineField("Messages", messages);
|
||||
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Bot.CommandPreconditions;
|
||||
using Geekbot.Commands.Karma;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.Extensions;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
|
||||
namespace Geekbot.Bot.Commands.User
|
||||
{
|
||||
[DisableInDirectMessage]
|
||||
public class Karma : GeekbotCommandBase
|
||||
{
|
||||
private readonly DatabaseContext _database;
|
||||
|
||||
public Karma(DatabaseContext database, IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager)
|
||||
{
|
||||
_database = database;
|
||||
}
|
||||
|
||||
[Command("good", RunMode = RunMode.Async)]
|
||||
[Summary("Increase Someones Karma")]
|
||||
public async Task Good([Summary("@someone")] IUser user)
|
||||
{
|
||||
await ChangeKarma(user, KarmaChange.Up);
|
||||
}
|
||||
|
||||
[Command("bad", RunMode = RunMode.Async)]
|
||||
[Summary("Decrease Someones Karma")]
|
||||
public async Task Bad([Summary("@someone")] IUser user)
|
||||
{
|
||||
await ChangeKarma(user, KarmaChange.Down);
|
||||
}
|
||||
|
||||
[Command("neutral", RunMode = RunMode.Async)]
|
||||
[Summary("Do nothing to someones Karma")]
|
||||
public async Task Neutral([Summary("@someone")] IUser user)
|
||||
{
|
||||
await ChangeKarma(user, KarmaChange.Same);
|
||||
}
|
||||
|
||||
private async Task ChangeKarma(IUser user, KarmaChange change)
|
||||
{
|
||||
try
|
||||
{
|
||||
var author = new Interactions.Resolved.User()
|
||||
{
|
||||
Id = Context.User.Id.ToString(),
|
||||
Username = Context.User.Username,
|
||||
Discriminator = Context.User.Discriminator,
|
||||
Avatar = Context.User.AvatarId,
|
||||
};
|
||||
var targetUser = new Interactions.Resolved.User()
|
||||
{
|
||||
Id = user.Id.ToString(),
|
||||
Username = user.Username,
|
||||
Discriminator = user.Discriminator,
|
||||
Avatar = user.AvatarId,
|
||||
};
|
||||
|
||||
var karma = new Geekbot.Commands.Karma.Karma(_database, Context.Guild.Id.AsLong());
|
||||
var res = await karma.ChangeKarma(author, targetUser, change);
|
||||
|
||||
await ReplyAsync(string.Empty, false, res.ToDiscordNetEmbed().Build());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
using Discord.Commands;
|
||||
using Geekbot.Bot.CommandPreconditions;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
using Geekbot.Core.Highscores;
|
||||
|
||||
namespace Geekbot.Bot.Commands.User
|
||||
{
|
||||
public class Rank : GeekbotCommandBase
|
||||
{
|
||||
private readonly IHighscoreManager _highscoreManager;
|
||||
private readonly DatabaseContext _database;
|
||||
|
||||
public Rank(DatabaseContext database, IErrorHandler errorHandler, IHighscoreManager highscoreManager, IGuildSettingsManager guildSettingsManager)
|
||||
: base(errorHandler, guildSettingsManager)
|
||||
{
|
||||
_database = database;
|
||||
_highscoreManager = highscoreManager;
|
||||
}
|
||||
|
||||
[Command("rank", RunMode = RunMode.Async)]
|
||||
[Summary("Get the highscore for various stats like message count, karma, correctly guessed roles, etc...")]
|
||||
[DisableInDirectMessage]
|
||||
public async Task RankCmd(
|
||||
[Summary("type")] string typeUnformated = "messages",
|
||||
[Summary("amount")] int amount = 10,
|
||||
[Summary("season")] string season = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var res = new Geekbot.Commands.Rank(_database, _highscoreManager)
|
||||
.Run(typeUnformated, amount, season, Context.Guild.Id, Context.Guild.Name);
|
||||
await ReplyAsync(res);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Bot.CommandPreconditions;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.Extensions;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
using Geekbot.Core.Levels;
|
||||
using Localization = Geekbot.Core.Localization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.User
|
||||
{
|
||||
public class Stats : GeekbotCommandBase
|
||||
{
|
||||
private readonly ILevelCalc _levelCalc;
|
||||
private readonly DatabaseContext _database;
|
||||
|
||||
public Stats(DatabaseContext database, IErrorHandler errorHandler, ILevelCalc levelCalc, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager)
|
||||
{
|
||||
_database = database;
|
||||
_levelCalc = levelCalc;
|
||||
}
|
||||
|
||||
[Command("stats", RunMode = RunMode.Async)]
|
||||
[Summary("Get information about this user")]
|
||||
[DisableInDirectMessage]
|
||||
public async Task User([Summary("@someone")] IUser user = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userInfo = user ?? Context.Message.Author;
|
||||
var userGuildInfo = (IGuildUser) userInfo;
|
||||
var createdAt = userInfo.CreatedAt;
|
||||
var joinedAt = userGuildInfo.JoinedAt.Value;
|
||||
var age = Math.Floor((DateTime.Now - createdAt).TotalDays);
|
||||
var joinedDayAgo = Math.Floor((DateTime.Now - joinedAt).TotalDays);
|
||||
|
||||
var messages = _database.Messages
|
||||
?.FirstOrDefault(e => e.GuildId.Equals(Context.Guild.Id.AsLong()) && e.UserId.Equals(userInfo.Id.AsLong()))
|
||||
?.MessageCount ?? 0;
|
||||
var guildMessages = _database.Messages
|
||||
?.Where(e => e.GuildId.Equals(Context.Guild.Id.AsLong()))
|
||||
.Select(e => e.MessageCount)
|
||||
.Sum() ?? 0;
|
||||
|
||||
var level = _levelCalc.GetLevel(messages);
|
||||
|
||||
var percent = Math.Round((double) (100 * messages) / guildMessages, 2);
|
||||
|
||||
var cookies = _database.Cookies
|
||||
?.FirstOrDefault(e => e.GuildId.Equals(Context.Guild.Id.AsLong()) && e.UserId.Equals(userInfo.Id.AsLong()))
|
||||
?.Cookies ?? 0;
|
||||
|
||||
var quotes = _database.Quotes.Count(e => e.GuildId.Equals(Context.Guild.Id.AsLong()) && e.UserId.Equals(userInfo.Id.AsLong()));
|
||||
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithAuthor(new EmbedAuthorBuilder()
|
||||
.WithIconUrl(userInfo.GetAvatarUrl())
|
||||
.WithName(userInfo.Username));
|
||||
eb.WithColor(new Color(221, 255, 119));
|
||||
|
||||
var karma = _database.Karma.FirstOrDefault(e =>
|
||||
e.GuildId.Equals(Context.Guild.Id.AsLong()) &&
|
||||
e.UserId.Equals(userInfo.Id.AsLong()));
|
||||
var correctRolls = _database.Rolls.FirstOrDefault(e =>
|
||||
e.GuildId.Equals(Context.Guild.Id.AsLong()) &&
|
||||
e.UserId.Equals(userInfo.Id.AsLong()));
|
||||
|
||||
eb.AddInlineField(Localization.Stats.OnDiscordSince,
|
||||
$"{createdAt.Day}.{createdAt.Month}.{createdAt.Year} ({age} {Localization.Stats.Days})")
|
||||
.AddInlineField(Localization.Stats.JoinedServer,
|
||||
$"{joinedAt.Day}.{joinedAt.Month}.{joinedAt.Year} ({joinedDayAgo} {Localization.Stats.Days})")
|
||||
.AddInlineField(Localization.Stats.Karma, karma?.Karma ?? 0)
|
||||
.AddInlineField(Localization.Stats.Level, level)
|
||||
.AddInlineField(Localization.Stats.MessagesSent, messages)
|
||||
.AddInlineField(Localization.Stats.ServerTotal, $"{percent}%");
|
||||
|
||||
if (correctRolls != null) eb.AddInlineField(Localization.Stats.GuessedRolls, correctRolls.Rolls);
|
||||
if (cookies > 0) eb.AddInlineField(Localization.Stats.Cookies, cookies);
|
||||
if (quotes > 0) eb.AddInlineField(Localization.Stats.Quotes, quotes);
|
||||
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Utils
|
||||
{
|
||||
public class AvatarGetter : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public AvatarGetter(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("avatar", RunMode = RunMode.Async)]
|
||||
[Summary("Get someones avatar")]
|
||||
public async Task GetAvatar([Remainder, Summary("@someone")] IUser user = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
user ??= Context.User;
|
||||
var url = user.GetAvatarUrl(ImageFormat.Auto, 1024);
|
||||
await ReplyAsync(url);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Utils.Changelog
|
||||
{
|
||||
public class Changelog : TransactionModuleBase
|
||||
{
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public Changelog(IErrorHandler errorHandler, DiscordSocketClient client)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
_client = client;
|
||||
}
|
||||
|
||||
[Command("changelog", RunMode = RunMode.Async)]
|
||||
[Summary("Show the latest 10 updates")]
|
||||
public async Task GetChangelog()
|
||||
{
|
||||
try
|
||||
{
|
||||
var commits = await HttpAbstractions.Get<List<CommitDto>>(new Uri("https://api.github.com/repos/pizzaandcoffee/geekbot.net/commits"));
|
||||
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithColor(new Color(143, 165, 102));
|
||||
eb.WithAuthor(new EmbedAuthorBuilder
|
||||
{
|
||||
IconUrl = _client.CurrentUser.GetAvatarUrl(),
|
||||
Name = "Latest Updates",
|
||||
Url = "https://geekbot.pizzaandcoffee.rocks/updates"
|
||||
});
|
||||
var sb = new StringBuilder();
|
||||
foreach (var commit in commits.Take(10))
|
||||
sb.AppendLine($"- {commit.Commit.Message} ({commit.Commit.Author.Date:yyyy-MM-dd})");
|
||||
eb.Description = sb.ToString();
|
||||
eb.WithFooter(new EmbedFooterBuilder
|
||||
{
|
||||
Text = $"List generated from github commits on {DateTime.Now:yyyy-MM-dd}"
|
||||
});
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
using System;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Utils.Changelog
|
||||
{
|
||||
public class CommitAuthorDto
|
||||
{
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonPropertyName("email")]
|
||||
public string Email { get; set; }
|
||||
|
||||
[JsonPropertyName("date")]
|
||||
public DateTimeOffset Date { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Utils.Changelog
|
||||
{
|
||||
public class CommitDto
|
||||
{
|
||||
[JsonPropertyName("commit")]
|
||||
public CommitInfoDto Commit { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Utils.Changelog
|
||||
{
|
||||
public class CommitInfoDto
|
||||
{
|
||||
[JsonPropertyName("author")]
|
||||
public CommitAuthorDto Author { get; set; }
|
||||
|
||||
[JsonPropertyName("message")]
|
||||
public string Message { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
using Localization = Geekbot.Core.Localization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Utils
|
||||
{
|
||||
public class Choose : GeekbotCommandBase
|
||||
{
|
||||
public Choose(IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager)
|
||||
{
|
||||
}
|
||||
|
||||
[Command("choose", RunMode = RunMode.Async)]
|
||||
[Summary("Let the bot choose for you, separate options with a semicolon.")]
|
||||
public async Task Command([Remainder] [Summary("option1;option2")]
|
||||
string choices)
|
||||
{
|
||||
try
|
||||
{
|
||||
var choicesArray = choices.Split(';');
|
||||
var choice = new Random().Next(choicesArray.Length);
|
||||
await ReplyAsync(string.Format(Localization.Choose.Choice, choicesArray[choice].Trim()));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.DiceParser;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Utils
|
||||
{
|
||||
public class Dice : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
private readonly IDiceParser _diceParser;
|
||||
|
||||
public Dice(IErrorHandler errorHandler, IDiceParser diceParser)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
_diceParser = diceParser;
|
||||
}
|
||||
|
||||
// ToDo: Separate representation and logic
|
||||
// ToDo: Translate
|
||||
[Command("dice", RunMode = RunMode.Async)]
|
||||
[Summary("Roll a dice. (use '!dice help' for a manual)")]
|
||||
public async Task RollCommand([Remainder] [Summary("input")] string diceInput = "1d20")
|
||||
{
|
||||
try
|
||||
{
|
||||
if (diceInput == "help")
|
||||
{
|
||||
await ShowDiceHelp();
|
||||
return;
|
||||
}
|
||||
|
||||
var parsed = _diceParser.Parse(diceInput);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($"{Context.User.Mention} :game_die:");
|
||||
foreach (var die in parsed.Dice)
|
||||
{
|
||||
sb.AppendLine($"**{die.DiceName}**");
|
||||
var diceResultList = new List<string>();
|
||||
var total = 0;
|
||||
|
||||
foreach (var roll in die.Roll())
|
||||
{
|
||||
diceResultList.Add(roll.ToString());
|
||||
total += roll.Result;
|
||||
}
|
||||
|
||||
sb.AppendLine(string.Join(" | ", diceResultList));
|
||||
|
||||
if (parsed.SkillModifier != 0)
|
||||
{
|
||||
sb.AppendLine($"Skill: {parsed.SkillModifier}");
|
||||
}
|
||||
|
||||
if (parsed.Options.ShowTotal)
|
||||
{
|
||||
var totalLine = $"Total: {total}";
|
||||
if (parsed.SkillModifier > 0)
|
||||
{
|
||||
totalLine += ($" (+{parsed.SkillModifier} = {total + parsed.SkillModifier})");
|
||||
}
|
||||
|
||||
if (parsed.SkillModifier < 0)
|
||||
{
|
||||
totalLine += ($" ({parsed.SkillModifier} = {total - parsed.SkillModifier})");
|
||||
}
|
||||
|
||||
sb.AppendLine(totalLine);
|
||||
}
|
||||
}
|
||||
|
||||
await Context.Channel.SendMessageAsync(sb.ToString());
|
||||
}
|
||||
catch (DiceException e)
|
||||
{
|
||||
await Context.Channel.SendMessageAsync($"**:warning: {e.DiceName} is invalid:** {e.Message}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ShowDiceHelp()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine("**__Examples__**");
|
||||
sb.AppendLine("```");
|
||||
sb.AppendLine("!dice - throw a 1d20");
|
||||
sb.AppendLine("!dice 1d12 - throw a 1d12");
|
||||
sb.AppendLine("!dice +1d20 - throw with advantage");
|
||||
sb.AppendLine("!dice -1d20 - throw with disadvantage");
|
||||
sb.AppendLine("!dice 1d20 +2 - throw with a +2 skill bonus");
|
||||
sb.AppendLine("!dice 1d20 -2 - throw with a -2 skill bonus");
|
||||
sb.AppendLine("!dice 8d6 - throw a fireball 🔥");
|
||||
sb.AppendLine("!dice 8d6 total - calculate the total");
|
||||
sb.AppendLine("!dice 2d20 6d6 2d12 - drop your dice pouch");
|
||||
sb.AppendLine("```");
|
||||
|
||||
await Context.Channel.SendMessageAsync(sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Converters;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Utils
|
||||
{
|
||||
public class Emojify : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public Emojify(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("emojify", RunMode = RunMode.Async)]
|
||||
[Summary("Emojify text")]
|
||||
public async Task Dflt([Remainder] [Summary("text")] string text)
|
||||
{
|
||||
try
|
||||
{
|
||||
var emojis = EmojiConverter.TextToEmoji(text);
|
||||
if (emojis.Length > 1999)
|
||||
{
|
||||
await ReplyAsync("I can't take that much at once!");
|
||||
return;
|
||||
}
|
||||
|
||||
await ReplyAsync($"{Context.User.Username}#{Context.User.Discriminator} said:");
|
||||
await ReplyAsync(emojis);
|
||||
try
|
||||
{
|
||||
await Context.Message.DeleteAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// bot may not have enough permission, doesn't matter if it fails
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Utils
|
||||
{
|
||||
public class Help : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public Help(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("help", RunMode = RunMode.Async)]
|
||||
[Summary("List all Commands")]
|
||||
public async Task GetHelp()
|
||||
{
|
||||
try
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine("For a list of all commands, please visit the following page");
|
||||
sb.AppendLine("https://geekbot.pizzaandcoffee.rocks/commands");
|
||||
var dm = await Context.User.CreateDMChannelAsync(RequestOptions.Default);
|
||||
await dm.SendMessageAsync(sb.ToString());
|
||||
await Context.Message.AddReactionAsync(new Emoji("✅"));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.Extensions;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Utils
|
||||
{
|
||||
public class Info : TransactionModuleBase
|
||||
{
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly CommandService _commands;
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public Info(IErrorHandler errorHandler, DiscordSocketClient client, CommandService commands)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
_client = client;
|
||||
_commands = commands;
|
||||
}
|
||||
|
||||
[Command("info", RunMode = RunMode.Async)]
|
||||
[Summary("Get Information about the bot")]
|
||||
public async Task BotInfo()
|
||||
{
|
||||
try
|
||||
{
|
||||
var eb = new EmbedBuilder();
|
||||
|
||||
var appInfo = await _client.GetApplicationInfoAsync();
|
||||
|
||||
eb.WithAuthor(new EmbedAuthorBuilder()
|
||||
.WithIconUrl(appInfo.IconUrl)
|
||||
.WithName($"{Constants.Name} V{Constants.BotVersion()}"));
|
||||
var uptime = DateTime.Now.Subtract(Process.GetCurrentProcess().StartTime);
|
||||
|
||||
eb.AddInlineField("Bot Name", _client.CurrentUser.Username);
|
||||
eb.AddInlineField("Bot Owner", $"{appInfo.Owner.Username}#{appInfo.Owner.Discriminator}");
|
||||
eb.AddInlineField("Library", $"Discord.NET {Constants.LibraryVersion()}");
|
||||
eb.AddInlineField("Uptime", $"{uptime.Days}D {uptime.Hours}H {uptime.Minutes}M {uptime.Seconds}S");
|
||||
eb.AddInlineField("Servers", Context.Client.GetGuildsAsync().Result.Count);
|
||||
eb.AddInlineField("Total Commands", _commands.Commands.Count());
|
||||
eb.AddField("Website", "https://geekbot.pizzaandcoffee.rocks/");
|
||||
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("uptime", RunMode = RunMode.Async)]
|
||||
[Summary("Get the Bot Uptime")]
|
||||
public async Task BotUptime()
|
||||
{
|
||||
try
|
||||
{
|
||||
var uptime = DateTime.Now.Subtract(Process.GetCurrentProcess().StartTime);
|
||||
await ReplyAsync($"{uptime.Days}D {uptime.Hours}H {uptime.Minutes}M {uptime.Seconds}S");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Utils
|
||||
{
|
||||
public class Lmgtfy : TransactionModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public Lmgtfy(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("lmgtfy", RunMode = RunMode.Async)]
|
||||
[Summary("Get a 'Let me google that for you' link")]
|
||||
public async Task GetUrl([Remainder] [Summary("question")] string question)
|
||||
{
|
||||
try
|
||||
{
|
||||
var encoded = HttpUtility.UrlEncode(question).Replace("%20", "+");
|
||||
await Context.Channel.SendMessageAsync($"<https://lmgtfy.com/?q={encoded}>");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
using System;
|
||||
using System.Data;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Utils.Quote
|
||||
{
|
||||
public class MessageLink
|
||||
{
|
||||
public readonly static Regex re = new Regex(
|
||||
@"https:\/\/((canary|ptb)\.)?discord(app)?.com\/channels\/(?<GuildId>\d{16,20})\/(?<ChannelId>\d{16,20})\/(?<MessageId>\d{16,20})",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase,
|
||||
new TimeSpan(0, 0, 2));
|
||||
|
||||
public ulong GuildId { get; set; }
|
||||
public ulong ChannelId { get; set; }
|
||||
public ulong MessageId { get; set; }
|
||||
|
||||
public MessageLink(string url)
|
||||
{
|
||||
var matches = re.Matches(url);
|
||||
|
||||
foreach (Match match in matches)
|
||||
{
|
||||
foreach (Group matchGroup in match.Groups)
|
||||
{
|
||||
switch (matchGroup.Name)
|
||||
{
|
||||
case "GuildId":
|
||||
GuildId = ulong.Parse(matchGroup.Value);
|
||||
break;
|
||||
case "ChannelId":
|
||||
ChannelId = ulong.Parse(matchGroup.Value);
|
||||
break;
|
||||
case "MessageId":
|
||||
MessageId = ulong.Parse(matchGroup.Value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsValid(string link)
|
||||
{
|
||||
return re.IsMatch(link);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,322 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Bot.CommandPreconditions;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Database.Models;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.Extensions;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
using Geekbot.Core.Polyfills;
|
||||
using Geekbot.Core.RandomNumberGenerator;
|
||||
using Geekbot.Core.UserRepository;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Sentry;
|
||||
using Constants = Geekbot.Core.Constants;
|
||||
using Localization = Geekbot.Core.Localization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Utils.Quote
|
||||
{
|
||||
[Group("quote")]
|
||||
[DisableInDirectMessage]
|
||||
public class Quote : GeekbotCommandBase
|
||||
{
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly bool _isDev;
|
||||
|
||||
public Quote(IErrorHandler errorHandler, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator, IGuildSettingsManager guildSettingsManager, IUserRepository userRepository)
|
||||
: base(errorHandler, guildSettingsManager)
|
||||
{
|
||||
_database = database;
|
||||
_randomNumberGenerator = randomNumberGenerator;
|
||||
_userRepository = userRepository;
|
||||
// to remove restrictions when developing
|
||||
_isDev = Constants.BotVersion() == "0.0.0-DEV";
|
||||
}
|
||||
|
||||
[Command]
|
||||
[Summary("Return a random quote from the database")]
|
||||
public async Task GetRandomQuote()
|
||||
{
|
||||
try
|
||||
{
|
||||
var getQuoteFromDbSpan = Transaction.StartChild("GetQuoteFromDB");
|
||||
var quote = _database.Quotes.FromSqlInterpolated($"select * from \"Quotes\" where \"GuildId\" = {Context.Guild.Id} order by random() limit 1");
|
||||
getQuoteFromDbSpan.Finish();
|
||||
|
||||
if (!quote.Any())
|
||||
{
|
||||
await ReplyAsync(Localization.Quote.NoQuotesFound);
|
||||
Transaction.Status = SpanStatus.NotFound;
|
||||
return;
|
||||
}
|
||||
|
||||
var buildQuoteEmbedSpan = Transaction.StartChild("BuildQuoteEmbed");
|
||||
var embed = QuoteBuilder(quote.FirstOrDefault());
|
||||
buildQuoteEmbedSpan.Finish();
|
||||
await ReplyAsync("", false, embed.Build());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context, "Whoops, seems like the quote was to edgy to return");
|
||||
Transaction.Status = SpanStatus.InternalError;
|
||||
}
|
||||
}
|
||||
|
||||
[Command("add")]
|
||||
[Alias("save")]
|
||||
[Summary("Add a quote from the last sent message by @user")]
|
||||
public async Task AddQuote([Summary("@someone")] IUser user)
|
||||
{
|
||||
await QuoteFromMention(user, true);
|
||||
}
|
||||
|
||||
[Command("make")]
|
||||
[Alias("preview")]
|
||||
[Summary("Preview a quote from the last sent message by @user")]
|
||||
public async Task ReturnSpecifiedQuote([Summary("@someone")] IUser user)
|
||||
{
|
||||
await QuoteFromMention(user, false);
|
||||
}
|
||||
|
||||
[Command("add")]
|
||||
[Alias("save")]
|
||||
[Summary("Add a quote from a message link")]
|
||||
public async Task AddQuote([Summary("message-link")] string messageLink)
|
||||
{
|
||||
await QuoteFromMessageLink(messageLink, true);
|
||||
}
|
||||
|
||||
[Command("make")]
|
||||
[Alias("preview")]
|
||||
[Summary("Preview a quote from a message link")]
|
||||
public async Task ReturnSpecifiedQuote([Summary("message-link")] string messageLink)
|
||||
{
|
||||
await QuoteFromMessageLink(messageLink, false);
|
||||
}
|
||||
|
||||
[Command("remove")]
|
||||
[RequireUserPermission(GuildPermission.ManageMessages)]
|
||||
[Summary("Remove a quote (user needs the 'ManageMessages' permission)")]
|
||||
public async Task RemoveQuote([Summary("quote-ID")] int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var quote = _database.Quotes.Where(e => e.GuildId == Context.Guild.Id.AsLong() && e.InternalId == id)?.FirstOrDefault();
|
||||
if (quote != null)
|
||||
{
|
||||
_database.Quotes.Remove(quote);
|
||||
await _database.SaveChangesAsync();
|
||||
var embed = QuoteBuilder(quote);
|
||||
await ReplyAsync(string.Format(Localization.Quote.Removed, id), false, embed.Build());
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyAsync(Localization.Quote.NotFoundWithId);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context, "I couldn't find a quote with that id :disappointed:");
|
||||
}
|
||||
}
|
||||
|
||||
[Command("stats")]
|
||||
[Summary("Show quote stats for this server")]
|
||||
public async Task GetQuoteStatsForServer()
|
||||
{
|
||||
try
|
||||
{
|
||||
// setup
|
||||
var eb = new EmbedBuilder();
|
||||
eb.Author = new EmbedAuthorBuilder()
|
||||
{
|
||||
IconUrl = Context.Guild.IconUrl,
|
||||
Name = $"{Context.Guild.Name} - {Localization.Quote.QuoteStats}"
|
||||
};
|
||||
|
||||
// gather data
|
||||
var totalQuotes = _database.Quotes.Count(row => row.GuildId == Context.Guild.Id.AsLong());
|
||||
if (totalQuotes == 0)
|
||||
{
|
||||
// no quotes, no stats, end of the road
|
||||
await ReplyAsync(Localization.Quote.NoQuotesFound);
|
||||
return;
|
||||
}
|
||||
|
||||
var mostQuotedPerson = _database.Quotes
|
||||
.Where(row => row.GuildId == Context.Guild.Id.AsLong())
|
||||
.GroupBy(row => row.UserId)
|
||||
.Select(row => new { userId = row.Key, amount = row.Count()})
|
||||
.OrderByDescending(row => row.amount)
|
||||
.First();
|
||||
var mostQuotedPersonUser = Context.Client.GetUserAsync(mostQuotedPerson.userId.AsUlong()).Result ?? new UserPolyfillDto {Username = "Unknown User"};
|
||||
|
||||
var quotesByYear = _database.Quotes
|
||||
.Where(row => row.GuildId == Context.Guild.Id.AsLong())
|
||||
.GroupBy(row => row.Time.Year)
|
||||
.Select(row => new { year = row.Key, amount = row.Count()})
|
||||
.OrderBy(row => row.year);
|
||||
|
||||
// add data to the embed
|
||||
eb.AddField(Localization.Quote.MostQuotesPerson, $"{mostQuotedPersonUser.Username} ({mostQuotedPerson.amount})");
|
||||
eb.AddInlineField(Localization.Quote.TotalQuotes, totalQuotes);
|
||||
|
||||
foreach (var year in quotesByYear)
|
||||
{
|
||||
eb.AddInlineField(year.year.ToString(), year.amount);
|
||||
}
|
||||
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task QuoteFromMention(IUser user, bool saveToDb)
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = Context.Channel.GetMessagesAsync().Flatten();
|
||||
var message = await list.FirstOrDefaultAsync(msg =>
|
||||
msg.Author.Id == user.Id &&
|
||||
msg.Embeds.Count == 0 &&
|
||||
msg.Id != Context.Message.Id &&
|
||||
!msg.Content.ToLower().StartsWith("!"));
|
||||
if (message == null) return;
|
||||
|
||||
await ProcessQuote(message, saveToDb);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context, $"No quoteable messages have been sent by {user.Username} in this channel");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async Task QuoteFromMessageLink(string messageLink, bool saveToDb)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!MessageLink.IsValid(messageLink))
|
||||
{
|
||||
await ReplyAsync(Localization.Quote.NotAValidMessageLink);
|
||||
return;
|
||||
}
|
||||
|
||||
var link = new MessageLink(messageLink);
|
||||
if (link.GuildId != Context.Guild.Id)
|
||||
{
|
||||
await ReplyAsync(Localization.Quote.OnlyQuoteFromSameServer);
|
||||
return;
|
||||
}
|
||||
|
||||
var channel = link.ChannelId == Context.Channel.Id
|
||||
? Context.Channel
|
||||
: await Context.Guild.GetTextChannelAsync(link.ChannelId);
|
||||
|
||||
var message = await channel.GetMessageAsync(link.MessageId);
|
||||
|
||||
await ProcessQuote(message, saveToDb);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ErrorHandler.HandleCommandException(e, Context, "I couldn't find that message :disappointed:");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ProcessQuote(IMessage message, bool saveToDb)
|
||||
{
|
||||
if (message.Author.Id == Context.Message.Author.Id && saveToDb && !_isDev)
|
||||
{
|
||||
await ReplyAsync(Localization.Quote.CannotSaveOwnQuotes);
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.Author.IsBot && saveToDb && !_isDev)
|
||||
{
|
||||
await ReplyAsync(Localization.Quote.CannotQuoteBots);
|
||||
return;
|
||||
}
|
||||
|
||||
var quote = CreateQuoteObject(message);
|
||||
if (saveToDb)
|
||||
{
|
||||
await _database.Quotes.AddAsync(quote);
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
|
||||
var embed = QuoteBuilder(quote);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
if (saveToDb) sb.AppendLine(Localization.Quote.QuoteAdded);
|
||||
|
||||
await ReplyAsync(sb.ToString(), false, embed.Build());
|
||||
}
|
||||
|
||||
private EmbedBuilder QuoteBuilder(QuoteModel quote)
|
||||
{
|
||||
var getEmbedUserSpan = Transaction.StartChild("GetEmbedUser");
|
||||
var user = Context.Client.GetUserAsync(quote.UserId.AsUlong()).Result;
|
||||
if (user == null)
|
||||
{
|
||||
var getEmbedUserFromRepoSpan = Transaction.StartChild("GetEmbedUserFromRepo");
|
||||
var fallbackUserFromRepo = _userRepository.Get(quote.UserId.AsUlong());
|
||||
user = new UserPolyfillDto()
|
||||
{
|
||||
Username = fallbackUserFromRepo?.Username ?? "Unknown User",
|
||||
AvatarUrl = fallbackUserFromRepo?.AvatarUrl
|
||||
};
|
||||
getEmbedUserFromRepoSpan.Finish();
|
||||
}
|
||||
getEmbedUserSpan.Finish();
|
||||
|
||||
var embedBuilderSpan = Transaction.StartChild("EmbedBuilder");
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithColor(new Color(143, 167, 232));
|
||||
eb.Title = quote.InternalId == 0
|
||||
? $"{user.Username} @ {quote.Time.Day}.{quote.Time.Month}.{quote.Time.Year}"
|
||||
: $"#{quote.InternalId} | {user.Username} @ {quote.Time.Day}.{quote.Time.Month}.{quote.Time.Year}";
|
||||
eb.Description = quote.Quote;
|
||||
eb.ThumbnailUrl = user.GetAvatarUrl();
|
||||
if (quote.Image != null) eb.ImageUrl = quote.Image;
|
||||
embedBuilderSpan.Finish();
|
||||
|
||||
return eb;
|
||||
}
|
||||
|
||||
private QuoteModel CreateQuoteObject(IMessage message)
|
||||
{
|
||||
string image;
|
||||
try
|
||||
{
|
||||
image = message.Attachments.First().Url;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
image = null;
|
||||
}
|
||||
|
||||
var last = _database.Quotes.Where(e => e.GuildId.Equals(Context.Guild.Id.AsLong())).OrderByDescending(e => e.InternalId).FirstOrDefault();
|
||||
var internalId = 0;
|
||||
if (last != null) internalId = last.InternalId + 1;
|
||||
return new QuoteModel()
|
||||
{
|
||||
InternalId = internalId,
|
||||
GuildId = Context.Guild.Id.AsLong(),
|
||||
UserId = message.Author.Id.AsLong(),
|
||||
Time = message.Timestamp.DateTime.ToUniversalTime(),
|
||||
Quote = message.Content,
|
||||
Image = image
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Utils.Quote
|
||||
{
|
||||
internal class QuoteObjectDto
|
||||
{
|
||||
public ulong UserId { get; set; }
|
||||
public string Quote { get; set; }
|
||||
public DateTime Time { get; set; }
|
||||
public string Image { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.Rest;
|
||||
using Discord.WebSocket;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Database.Models;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
using Geekbot.Core.Logger;
|
||||
|
||||
namespace Geekbot.Bot.Handlers
|
||||
{
|
||||
public class CommandHandler
|
||||
{
|
||||
private readonly IDiscordClient _client;
|
||||
private readonly IGeekbotLogger _logger;
|
||||
private readonly IServiceProvider _servicesProvider;
|
||||
private readonly CommandService _commands;
|
||||
private readonly RestApplication _applicationInfo;
|
||||
private readonly IGuildSettingsManager _guildSettingsManager;
|
||||
private readonly List<ulong> _ignoredServers;
|
||||
|
||||
public CommandHandler(IDiscordClient client, IGeekbotLogger logger, IServiceProvider servicesProvider, CommandService commands, RestApplication applicationInfo,
|
||||
IGuildSettingsManager guildSettingsManager)
|
||||
{
|
||||
_client = client;
|
||||
_logger = logger;
|
||||
_servicesProvider = servicesProvider;
|
||||
_commands = commands;
|
||||
_applicationInfo = applicationInfo;
|
||||
_guildSettingsManager = guildSettingsManager;
|
||||
|
||||
// Some guilds only want very specific functionally without any of the commands, a quick hack that solves that "short term"
|
||||
// ToDo: create a clean solution for this...
|
||||
_ignoredServers = new List<ulong>
|
||||
{
|
||||
228623803201224704, // SwitzerLAN
|
||||
// 169844523181015040, // EEvent
|
||||
248531441548263425, // MYI
|
||||
110373943822540800 // Discord Bots
|
||||
};
|
||||
}
|
||||
|
||||
public Task RunCommand(SocketMessage messageParam)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!(messageParam is SocketUserMessage message)) return Task.CompletedTask;
|
||||
if (message.Author.IsBot) return Task.CompletedTask;
|
||||
|
||||
ulong guildId = message.Author switch
|
||||
{
|
||||
SocketGuildUser user => user.Guild.Id,
|
||||
_ => 0 // DM Channel
|
||||
};
|
||||
|
||||
if (IsIgnoredGuild(guildId, message.Author.Id)) return Task.CompletedTask;
|
||||
|
||||
var lowCaseMsg = message.ToString().ToLower();
|
||||
if (ShouldHui(lowCaseMsg, guildId))
|
||||
{
|
||||
message.Channel.SendMessageAsync("hui!!!");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
if (ShouldPong(lowCaseMsg, guildId))
|
||||
{
|
||||
message.Channel.SendMessageAsync("pong");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
var argPos = 0;
|
||||
if (!IsCommand(message, ref argPos)) return Task.CompletedTask;
|
||||
|
||||
ExecuteCommand(message, argPos);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(LogSource.Geekbot, "Failed to Process Message", e);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void ExecuteCommand(IUserMessage message, int argPos)
|
||||
{
|
||||
var context = new CommandContext(_client, message);
|
||||
_commands.ExecuteAsync(context, argPos, _servicesProvider);
|
||||
_logger.Information(LogSource.Command, context.Message.Content.Split(" ")[0].Replace("!", ""), SimpleConextConverter.ConvertContext(context));
|
||||
}
|
||||
|
||||
private bool IsIgnoredGuild(ulong guildId, ulong authorId)
|
||||
{
|
||||
if (!_ignoredServers.Contains(guildId)) return false;
|
||||
return authorId == _applicationInfo.Owner.Id;
|
||||
}
|
||||
|
||||
private bool IsCommand(IUserMessage message, ref int argPos)
|
||||
{
|
||||
return message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos);
|
||||
}
|
||||
|
||||
private bool ShouldPong(string lowerCaseMessage, ulong guildId)
|
||||
{
|
||||
if (!lowerCaseMessage.StartsWith("ping ") && !lowerCaseMessage.Equals("ping")) return false;
|
||||
if (guildId == 0) return true;
|
||||
return GetGuildSettings(guildId)?.Ping ?? false;
|
||||
}
|
||||
|
||||
private bool ShouldHui(string lowerCaseMessage, ulong guildId)
|
||||
{
|
||||
if (!lowerCaseMessage.StartsWith("hui")) return false;
|
||||
if (guildId == 0) return true;
|
||||
return GetGuildSettings(guildId)?.Hui ?? false;
|
||||
}
|
||||
|
||||
private GuildSettingsModel GetGuildSettings(ulong guildId)
|
||||
{
|
||||
return _guildSettingsManager.GetSettings(guildId, false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Extensions;
|
||||
using Geekbot.Core.Logger;
|
||||
|
||||
namespace Geekbot.Bot.Handlers
|
||||
{
|
||||
public class MessageDeletedHandler
|
||||
{
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly IGeekbotLogger _logger;
|
||||
private readonly IDiscordClient _client;
|
||||
|
||||
public MessageDeletedHandler(DatabaseContext database, IGeekbotLogger logger, IDiscordClient client)
|
||||
{
|
||||
_database = database;
|
||||
_logger = logger;
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public async Task HandleMessageDeleted(Cacheable<IMessage, ulong> message, Cacheable<IMessageChannel, ulong> cacheableMessageChannel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var guildSocketData = ((IGuildChannel) cacheableMessageChannel.Value).Guild;
|
||||
var guild = _database.GuildSettings.FirstOrDefault(g => g.GuildId.Equals(guildSocketData.Id.AsLong()));
|
||||
if ((guild?.ShowDelete ?? false) && guild?.ModChannel != 0)
|
||||
{
|
||||
var modChannelSocket = (ISocketMessageChannel) await _client.GetChannelAsync(guild.ModChannel.AsUlong());
|
||||
var sb = new StringBuilder();
|
||||
if (message.Value != null)
|
||||
{
|
||||
sb.AppendLine($"The following message from {message.Value.Author.Username}#{message.Value.Author.Discriminator} was deleted in <#{cacheableMessageChannel.Id}>");
|
||||
sb.AppendLine(message.Value.Content);
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine("Someone deleted a message, the message was not cached...");
|
||||
}
|
||||
|
||||
await modChannelSocket.SendMessageAsync(sb.ToString());
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(LogSource.Geekbot, "Failed to send delete message...", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using Geekbot.Core.ReactionListener;
|
||||
|
||||
namespace Geekbot.Bot.Handlers
|
||||
{
|
||||
public class ReactionHandler
|
||||
{
|
||||
private readonly IReactionListener _reactionListener;
|
||||
|
||||
public ReactionHandler(IReactionListener reactionListener)
|
||||
{
|
||||
_reactionListener = reactionListener;
|
||||
}
|
||||
|
||||
public Task Added(Cacheable<IUserMessage, ulong> cacheableUserMessage, Cacheable<IMessageChannel, ulong> cacheableMessageChannel, SocketReaction reaction)
|
||||
{
|
||||
if (reaction.User.Value.IsBot) return Task.CompletedTask;
|
||||
if (!_reactionListener.IsListener(reaction.MessageId)) return Task.CompletedTask;
|
||||
_reactionListener.GiveRole(cacheableMessageChannel.Value, reaction);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Removed(Cacheable<IUserMessage, ulong> cacheableUserMessage, Cacheable<IMessageChannel, ulong> cacheableMessageChannel, SocketReaction reaction)
|
||||
{
|
||||
if (reaction.User.Value.IsBot) return Task.CompletedTask;
|
||||
if (!_reactionListener.IsListener(reaction.MessageId)) return Task.CompletedTask;
|
||||
_reactionListener.RemoveRole(cacheableMessageChannel.Value, reaction);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.WebSocket;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Database.Models;
|
||||
using Geekbot.Core.Extensions;
|
||||
using Geekbot.Core.Highscores;
|
||||
using Geekbot.Core.Logger;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Geekbot.Bot.Handlers
|
||||
{
|
||||
public class StatsHandler
|
||||
{
|
||||
private readonly IGeekbotLogger _logger;
|
||||
private readonly DatabaseContext _database;
|
||||
private string _season;
|
||||
|
||||
public StatsHandler(IGeekbotLogger logger, DatabaseContext database)
|
||||
{
|
||||
_logger = logger;
|
||||
_database = database;
|
||||
_season = SeasonsUtils.GetCurrentSeason();
|
||||
|
||||
var timer = new System.Timers.Timer()
|
||||
{
|
||||
Enabled = true,
|
||||
AutoReset = true,
|
||||
Interval = TimeSpan.FromMinutes(5).TotalMilliseconds
|
||||
};
|
||||
timer.Elapsed += (sender, args) =>
|
||||
{
|
||||
var current = SeasonsUtils.GetCurrentSeason();
|
||||
if (current == _season) return;
|
||||
_season = SeasonsUtils.GetCurrentSeason();
|
||||
};
|
||||
}
|
||||
|
||||
public async Task UpdateStats(SocketMessage message)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (message == null) return;
|
||||
if (message.Channel.Name.StartsWith('@'))
|
||||
{
|
||||
_logger.Information(LogSource.Message, $"[DM-Channel] {message.Content}", SimpleConextConverter.ConvertSocketMessage(message, true));
|
||||
return;
|
||||
}
|
||||
|
||||
var channel = (SocketGuildChannel) message.Channel;
|
||||
|
||||
// ignore the discord bots server
|
||||
// ToDo: create a clean solution for this...
|
||||
if (channel.Guild.Id == 110373943822540800)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await UpdateTotalTable(message, channel);
|
||||
await UpdateSeasonsTable(message, channel);
|
||||
|
||||
|
||||
if (message.Author.IsBot) return;
|
||||
_logger.Information(LogSource.Message, message.Content, SimpleConextConverter.ConvertSocketMessage(message));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(LogSource.Message, "Could not process message stats", e);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateTotalTable(SocketMessage message, SocketGuildChannel channel)
|
||||
{
|
||||
var rowId = await _database.Database.ExecuteSqlRawAsync(
|
||||
"UPDATE \"Messages\" SET \"MessageCount\" = \"MessageCount\" + 1 WHERE \"GuildId\" = {0} AND \"UserId\" = {1}",
|
||||
channel.Guild.Id.AsLong(),
|
||||
message.Author.Id.AsLong()
|
||||
);
|
||||
|
||||
if (rowId == 0)
|
||||
{
|
||||
await _database.Messages.AddAsync(new MessagesModel
|
||||
{
|
||||
UserId = message.Author.Id.AsLong(),
|
||||
GuildId = channel.Guild.Id.AsLong(),
|
||||
MessageCount = 1
|
||||
});
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateSeasonsTable(SocketMessage message, SocketGuildChannel channel)
|
||||
{
|
||||
var rowId = await _database.Database.ExecuteSqlRawAsync(
|
||||
"UPDATE \"MessagesSeasons\" SET \"MessageCount\" = \"MessageCount\" + 1 WHERE \"GuildId\" = {0} AND \"UserId\" = {1} AND \"Season\" = {2}",
|
||||
channel.Guild.Id.AsLong(),
|
||||
message.Author.Id.AsLong(),
|
||||
_season
|
||||
);
|
||||
|
||||
if (rowId == 0)
|
||||
{
|
||||
await _database.MessagesSeasons.AddAsync(new MessageSeasonsModel()
|
||||
{
|
||||
UserId = message.Author.Id.AsLong(),
|
||||
GuildId = channel.Guild.Id.AsLong(),
|
||||
Season = _season,
|
||||
MessageCount = 1
|
||||
});
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Rest;
|
||||
using Discord.WebSocket;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Extensions;
|
||||
using Geekbot.Core.Logger;
|
||||
using Geekbot.Core.UserRepository;
|
||||
|
||||
namespace Geekbot.Bot.Handlers
|
||||
{
|
||||
public class UserHandler
|
||||
{
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly IGeekbotLogger _logger;
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly IDiscordClient _client;
|
||||
|
||||
public UserHandler(IUserRepository userRepository, IGeekbotLogger logger, DatabaseContext database, IDiscordClient client)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
_logger = logger;
|
||||
_database = database;
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public async Task Joined(SocketGuildUser user)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userRepoUpdate = _userRepository.Update(user);
|
||||
_logger.Information(LogSource.Geekbot, $"{user.Username} ({user.Id}) joined {user.Guild.Name} ({user.Guild.Id})");
|
||||
|
||||
if (!user.IsBot)
|
||||
{
|
||||
var guildSettings = _database.GuildSettings.FirstOrDefault(guild => guild.GuildId == user.Guild.Id.AsLong());
|
||||
var message = guildSettings?.WelcomeMessage;
|
||||
if (string.IsNullOrEmpty(message)) return;
|
||||
message = message.Replace("$user", user.Mention);
|
||||
|
||||
var fallbackSender = new Func<Task<RestUserMessage>>(() => user.Guild.DefaultChannel.SendMessageAsync(message));
|
||||
if (guildSettings.WelcomeChannel != 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
var target = await _client.GetChannelAsync(guildSettings.WelcomeChannel.AsUlong());
|
||||
var channel = target as ISocketMessageChannel;
|
||||
await channel.SendMessageAsync(message);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(LogSource.Geekbot, "Failed to send welcome message to user defined welcome channel", e);
|
||||
await fallbackSender();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await fallbackSender();
|
||||
}
|
||||
}
|
||||
|
||||
await userRepoUpdate;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(LogSource.Geekbot, "Failed to send welcome message", e);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Updated(SocketUser oldUser, SocketUser newUser)
|
||||
{
|
||||
await _userRepository.Update(newUser);
|
||||
}
|
||||
|
||||
public async Task Left(SocketGuild socketGuild, SocketUser socketUser)
|
||||
{
|
||||
try
|
||||
{
|
||||
var guild = _database.GuildSettings.FirstOrDefault(g => g.GuildId.Equals(socketGuild.Id.AsLong()));
|
||||
if (guild?.ShowLeave ?? false)
|
||||
{
|
||||
var modChannelSocket = (ISocketMessageChannel) await _client.GetChannelAsync(guild.ModChannel.AsUlong());
|
||||
await modChannelSocket.SendMessageAsync($"{socketUser.Username}#{socketUser.Discriminator} left the server");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(LogSource.Geekbot, "Failed to send leave message", e);
|
||||
}
|
||||
|
||||
_logger.Information(LogSource.Geekbot, $"{socketUser.Username} ({socketUser.Id}) joined {socketGuild.Name} ({socketGuild.Id})");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
https://i2.wp.com/epicureandculture.com/wp-content/uploads/2014/12/shutterstock_172040546.jpg
|
||||
http://www.bakespace.com/images/large/5d79070cf21b2f33c3a1dd4336cb27d2.jpeg
|
||||
http://food.fnr.sndimg.com/content/dam/images/food/fullset/2015/5/7/1/SD1B43_croissants-recipe_s4x3.jpg.rend.hgtvcom.616.462.suffix/1431052139248.jpeg
|
||||
http://img.taste.com.au/u-Bwjfm_/taste/2016/11/mini-croissants-with-3-fillings-14692-1.jpeg
|
||||
https://media.newyorker.com/photos/590974702179605b11ad8096/16:9/w_1200,h_630,c_limit/Gopnik-TheMurkyMeaningsofStraightenedOutCroissants.jpg
|
||||
https://storage.cpstatic.ch/storage/og_image/laugengipfel--425319.jpg
|
||||
https://c1.staticflickr.com/3/2835/10874180753_2b2916e3ce_b.jpg
|
||||
https://www.spatz-dessert.ch/image_upload/Laugengipfel.jpg
|
||||
http://www.baeckerei-meier.ch/images/p005_1_03.png
|
||||
http://i.huffpost.com/gen/1278175/thumbs/o-CROISSANT-facebook.jpg
|
|
@ -1,8 +0,0 @@
|
|||
https://pre00.deviantart.net/dcde/th/pre/i/2018/247/8/1/dabbing_pug_cute_dab_dance_by_manekibb-dcm2lvd.png
|
||||
https://banner2.kisspng.com/20180625/xfv/kisspng-squidward-tentacles-dab-desktop-wallpaper-dab-emoji-5b31a97a839bf2.6353972915299813065391.jpg
|
||||
https://djbooth.net/.image/t_share/MTUzNDg2MDIzOTU4NzM0NzA1/life-death-of-dab-dancejpg.jpg
|
||||
https://res.cloudinary.com/teepublic/image/private/s--gfsWHvaH--/t_Preview/b_rgb:262c3a,c_limit,f_jpg,h_630,q_90,w_630/v1493209189/production/designs/1524888_1.jpg
|
||||
https://i1.wp.com/fortniteskins.net/wp-content/uploads/2018/04/dab-skin-1.png?quality=90&strip=all&ssl=1
|
||||
https://i.pinimg.com/originals/12/d4/0a/12d40a8fc66b7a7ea8b9044ee0303974.png
|
||||
https://images.bewakoof.com/t540/dab-penguin-boyfriend-t-shirt-women-s-printed-boyfriend-t-shirts-196918-1538034349.jpg
|
||||
https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSKH1FLh5L3pOR2tamx-5OBqm_W2FFl8F7gteTAs2vMowwJ1Y32
|
File diff suppressed because it is too large
Load diff
|
@ -1,20 +0,0 @@
|
|||
https://i.ytimg.com/vi/qF6OOGuT_hI/maxresdefault.jpg
|
||||
https://static.tumblr.com/bb34d8f163098ad1daafcffbdbb03975/rk23uap/Nwwp0rmi2/tumblr_static_tumblr_static__640.jpg
|
||||
https://www.popsci.com/sites/popsci.com/files/styles/1000_1x_/public/import/2013/images/2013/09/redfoxyawn.jpg?itok=yRkSVe8T
|
||||
https://hdqwalls.com/wallpapers/wild-fox-art.jpg
|
||||
https://i.imgur.com/ktK9yXX.jpg
|
||||
http://4.bp.blogspot.com/-Hz-o_KYj3Xk/Vlm2mwbztjI/AAAAAAAA8Ss/jbH5ovjmC9A/s1600/ScreenShot5502.jpg
|
||||
https://wallpaperscraft.com/image/fox_forest_grass_117190_540x960.jpg
|
||||
https://orig00.deviantart.net/2feb/f/2013/137/a/f/fox_and_curious_squirrel_by_tamarar-d65ju8d.jpg
|
||||
http://www.tehcute.com/pics/201401/little-fox-big.jpg
|
||||
https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR6QXB1APLdUsyzO39kPvhnC9cOvcwzEtsxown9QjWilWppia2mwg
|
||||
https://www.wildlifeaid.org.uk/wp-content/uploads/2016/03/FP9_July09.jpg
|
||||
https://upload.wikimedia.org/wikipedia/commons/thumb/b/bb/Vulpes_vulpes_ssp_fulvus_6568085.jpg/1200px-Vulpes_vulpes_ssp_fulvus_6568085.jpg
|
||||
http://images.hellogiggles.com/uploads/2017/06/10023347/fox1.jpg
|
||||
https://i.ytimg.com/vi/mtroFou8Xb4/maxresdefault.jpg
|
||||
http://wallpapers-best.com/uploads/posts/2015-09/20_fox.jpg
|
||||
https://www.whats-your-sign.com/wp-content/uploads/2018/02/RedFoxSymbolism4.jpg
|
||||
https://cdn.zmescience.com/wp-content/uploads/2016/09/8505162700_11394c3f6a_b.jpg
|
||||
http://wallpapers-best.com/uploads/posts/2015-09/18_fox.jpg
|
||||
https://s.abcnews.com/images/General/red-fox-new-jersey-gty-jt-191119_hpMain_16x9_992.jpg
|
||||
https://i.ytimg.com/vi/ClNRWL_9L8s/maxresdefault.jpg
|
|
@ -1,12 +0,0 @@
|
|||
https://upload.wikimedia.org/wikipedia/commons/thumb/0/0f/Grosser_Panda.JPG/1200px-Grosser_Panda.JPG
|
||||
https://c402277.ssl.cf1.rackcdn.com/photos/13100/images/featured_story/BIC_128.png?1485963152
|
||||
https://nationalzoo.si.edu/sites/default/files/styles/slide_1400x700/public/support/adopt/giantpanda-03.jpg?itok=3EdEO0Vi
|
||||
https://media4.s-nbcnews.com/j/newscms/2016_36/1685951/ss-160826-twip-05_8cf6d4cb83758449fd400c7c3d71aa1f.nbcnews-ux-2880-1000.jpg
|
||||
https://ichef-1.bbci.co.uk/news/660/cpsprodpb/169F6/production/_91026629_gettyimages-519508400.jpg
|
||||
https://cdn.history.com/sites/2/2017/03/GettyImages-157278376.jpg
|
||||
https://tctechcrunch2011.files.wordpress.com/2015/11/panda.jpg
|
||||
http://www.nationalgeographic.com/content/dam/magazine/rights-exempt/2016/08/departments/panda-mania-12.jpg
|
||||
http://animals.sandiegozoo.org/sites/default/files/2016-09/panda1_10.jpg
|
||||
http://kids.nationalgeographic.com/content/dam/kids/photos/animals/Mammals/A-G/giant-panda-eating.adapt.945.1.jpg
|
||||
https://static.independent.co.uk/s3fs-public/thumbnails/image/2015/10/08/15/Hong-Kong-pandas.jpg
|
||||
https://3sn4dm1qd6i72l8a4r2ig7fl-wpengine.netdna-ssl.com/wp-content/uploads/2016/11/panda_lunlun_ZA_2083-b.jpg
|
|
@ -1,15 +0,0 @@
|
|||
https://www.birdlife.org/sites/default/files/styles/1600/public/slide.jpg?itok=HRhQfA1S
|
||||
http://experimentexchange.com/wp-content/uploads/2016/07/penguins-fact.jpg
|
||||
http://www.antarctica.gov.au/__data/assets/image/0011/147737/varieties/antarctic.jpg
|
||||
https://images.justwatch.com/backdrop/8611153/s1440/pingu
|
||||
http://4.bp.blogspot.com/-VhmPPCcZnwA/TWR303DSAuI/AAAAAAAAABU/eSSokmd376s/s1600/2-Penguins-penguins-4234010-1280-1024.jpg
|
||||
https://media.glamour.com/photos/56959e35d9dab9ff41b308a0/master/pass/inspired-2015-02-gentoo-penguin-main.jpg
|
||||
https://indiansciencejournal.files.wordpress.com/2012/04/emperor-penguin-credit-british-antarctic-survey.jpg
|
||||
https://fthmb.tqn.com/7cd9Q3LSapEShHq2mKvQgSPr_tc=/2250x1500/filters:fill(auto,1)/149267744-56a008755f9b58eba4ae8f46.jpg
|
||||
https://blogs.voanews.com/science-world/files/2014/07/11240219084_941dfbf66e_b.jpg
|
||||
https://blogs.biomedcentral.com/bmcseriesblog/wp-content/uploads/sites/9/2015/11/IMG_5391-2.jpg
|
||||
https://i2-prod.mirror.co.uk/incoming/article11682518.ece/ALTERNATES/s615/Emperor-penguins-on-ice.jpg
|
||||
https://www.gannett-cdn.com/presto/2019/04/15/PPHX/8dfe0433-c22c-4458-9ba8-3aab866774f8-Penguins5cad7bfd107a4.jpg?crop=5759,3224,x0,y0&width=3200&height=1680&fit=bounds
|
||||
http://4.bp.blogspot.com/_FNQgkfCwYxs/S82jBAxMVEI/AAAAAAAAAns/_3lAuJhUfcs/s1600/311785583_af8f2d1ea7_o.jpg
|
||||
http://wallsdesk.com/wp-content/uploads/2017/01/Pictures-of-Penguin-.jpg
|
||||
http://2.bp.blogspot.com/_W90V87w3sr8/TP3RPYwrrjI/AAAAAAAAAXk/riN0GwRwhFM/s1600/leap-of-faith-adelie-penguin-pictures.jpg
|
|
@ -1,14 +0,0 @@
|
|||
https://i.pinimg.com/736x/0a/a7/8a/0aa78af25e114836e1a42585fb7b09ed--funny-pumpkins-pumkin-carving.jpg
|
||||
http://wdy.h-cdn.co/assets/16/31/980x1470/gallery-1470321728-shot-two-021.jpg
|
||||
http://images6.fanpop.com/image/photos/38900000/Jack-o-Lantern-halloween-38991566-500-415.jpg
|
||||
http://ghk.h-cdn.co/assets/15/37/1441834730-pumpkin-carve-2.jpg
|
||||
http://diy.sndimg.com/content/dam/images/diy/fullset/2011/7/26/1/iStock-10761186_halloween-pumpkin-in-garden_s4x3.jpg.rend.hgtvcom.966.725.suffix/1420851319631.jpeg
|
||||
https://www.digsdigs.com/photos/2009/10/100-halloween-pumpkin-carving-ideas-12.jpg
|
||||
https://i.pinimg.com/736x/59/8a/0f/598a0fbf789631b76c1ffd4443194d8e--halloween-pumpkins-fall-halloween.jpg
|
||||
http://i.huffpost.com/gen/1405530/images/o-PUMPKINS-facebook.jpg
|
||||
https://www.reviewjournal.com/wp-content/uploads/2016/10/web1_thinkstockphotos-491684958_7239666.jpg
|
||||
https://img.sunset02.com/sites/default/files/1494265591/pumpkins-growing-on-farm-getty-sun-0517.jpg
|
||||
https://toronto.citynews.ca/wp-content/blogs.dir/sites/10/2015/10/06/pumpkin-patch.jpg
|
||||
http://i.huffpost.com/gen/3494726/images/o-PUMPKIN-facebook.jpg
|
||||
https://servingjoy.com/wp-content/uploads/2014/12/Beautiful-autumn-halloween-pumpkins.jpg
|
||||
https://www.history.com/.image/t_share/MTU3ODc5MDg2NDI4OTg4NzQ1/still-life-of-a-jack-o-lantern.jpg
|
|
@ -1,25 +0,0 @@
|
|||
https://public-media.smithsonianmag.com/filer/52/f9/52f93262-c29b-4a4f-b031-0c7ad145ed5f/42-33051942.jpg
|
||||
http://images5.fanpop.com/image/photos/30700000/Squirrel-squirrels-30710732-400-300.jpg
|
||||
http://i.dailymail.co.uk/i/pix/2016/02/24/16/158F7E7C000005DC-3462228-image-a-65_1456331226865.jpg
|
||||
http://2.bp.blogspot.com/-egfnMhUb8tg/T_dAIu1m6cI/AAAAAAAAPPU/v4x9q4WqWl8/s640/cute-squirrel-hey-watcha-thinkin-about.jpg
|
||||
https://upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Squirrel_posing.jpg/287px-Squirrel_posing.jpg
|
||||
https://i.pinimg.com/736x/51/db/9b/51db9bad4a87d445d321923c7d56b501--red-squirrel-animal-kingdom.jpg
|
||||
https://i.pinimg.com/736x/ce/9c/59/ce9c5990b193046400d98724595cdaf3--red-squirrel-chipmunks.jpg
|
||||
https://www.brooklynpaper.com/assets/photos/40/30/dtg-squirrel-attacks-prospect-park-patrons-2017-07-28-bk01_z.jpg
|
||||
https://i.pinimg.com/736x/b4/5c/0d/b45c0d00b1a57e9f84f27f13cb019001--baby-squirrel-red-squirrel.jpg
|
||||
https://i.pinimg.com/736x/0f/75/87/0f7587bb613ab524763afe8c9a532e5c--cute-squirrel-squirrels.jpg
|
||||
http://cdn.images.express.co.uk/img/dynamic/128/590x/Grey-squirrel-828838.jpg
|
||||
http://www.lovethispic.com/uploaded_images/79964-Squirrel-Smelling-A-Flower.jpg
|
||||
https://i.pinimg.com/736x/23/d5/f9/23d5f9868f7d76c79c49bef53ae08f7f--squirrel-funny-red-squirrel.jpg
|
||||
https://i.ytimg.com/vi/pzUs0DdzK3Y/hqdefault.jpg
|
||||
https://i.pinimg.com/736x/e2/16/bb/e216bba53f80fc8e0111d371e9850159--funny-squirrels-cute-squirrel.jpg
|
||||
https://i.pinimg.com/736x/52/43/c9/5243c93377245be1f686218c266d775c--funny-squirrel-baby-squirrel.jpg
|
||||
https://i.pinimg.com/736x/0c/be/1d/0cbe1da8ad2c0cf3882a806b6fd88965--cute-pictures-funny-animal-pictures.jpg
|
||||
https://i.pinimg.com/736x/1c/7d/4f/1c7d4f067a10066aad802ce5ac468d71--group-boards-a-squirrel.jpg
|
||||
https://i.pinimg.com/736x/d6/42/12/d64212cc6221916db4173962bf6c131a--cute-squirrel-baby-squirrel.jpg
|
||||
https://i.pinimg.com/736x/da/0d/fe/da0dfe93bb26887795f906e8fa97d68e--secret-squirrel-cute-squirrel.jpg
|
||||
http://2.bp.blogspot.com/-HLieBqEuQoM/UDkRmeyzB5I/AAAAAAAABHs/RtsEynn5t6Y/s1600/hd-squirrel-wallpaper-with-a-brown-squirrel-eating-watermelon-wallpapers-backgrounds-pictures-photos.jpg
|
||||
http://img15.deviantart.net/9c50/i/2011/213/c/9/just_taking_it_easy_by_lou_in_canada-d42do3d.jpg
|
||||
https://insider.si.edu/wp-content/uploads/2018/01/Chipmunk-Photo-Mark-Rounds.jpg
|
||||
https://media.mnn.com/assets/images/2014/12/gray-squirrel-uc-berkeley.jpg.1080x0_q100_crop-scale.jpg
|
||||
https://citywildlife.org/wp-content/uploads/Juvenile-squirrel.jpg
|
|
@ -1,20 +0,0 @@
|
|||
https://i.guim.co.uk/img/media/6b9be13031738e642f93f9271f3592044726a9b1/0_0_2863_1610/2863.jpg?w=640&h=360&q=55&auto=format&usm=12&fit=max&s=85f3b33cc158b5aa120c143dae1916ed
|
||||
http://cf.ltkcdn.net/small-pets/images/std/212089-676x450-Turtle-feeding-on-leaf.jpg
|
||||
https://c402277.ssl.cf1.rackcdn.com/photos/419/images/story_full_width/HI_287338Hero.jpg?1433950119
|
||||
https://www.cdc.gov/salmonella/agbeni-08-17/images/turtle.jpg
|
||||
https://cdn.arstechnica.net/wp-content/uploads/2017/08/GettyImages-524757168.jpg
|
||||
http://pmdvod.nationalgeographic.com/NG_Video/595/319/4504517_098_05_TOS_thumbnail_640x360_636296259676.jpg
|
||||
http://s7d2.scene7.com/is/image/PetSmart/ARTHMB-CleaningYourTortoiseOrTurtlesHabitat-20160818?$AR1104$
|
||||
https://fthmb.tqn.com/9VGWzK_GWlvrjxtdFPX6EJxOq24=/960x0/filters:no_upscale()/133605352-56a2bce53df78cf7727960db.jpg
|
||||
https://www.wildgratitude.com/wp-content/uploads/2015/07/turtle-spirit-animal1.jpg
|
||||
http://www.backwaterreptiles.com/images/turtles/red-eared-slider-turtle-for-sale.jpg
|
||||
http://turtlebackzoo.com/wp-content/uploads/2016/07/exhibit-headers_0008_SOUTH-AMERICA-600x400.jpg
|
||||
https://i.pinimg.com/736x/dd/4e/7f/dd4e7f2f921ac28b1d5a59174d477131--cute-baby-sea-turtles-adorable-turtles.jpg
|
||||
http://kids.nationalgeographic.com/content/dam/kids/photos/animals/Reptiles/A-G/green-sea-turtle-closeup-underwater.adapt.945.1.jpg
|
||||
https://fthmb.tqn.com/nirxHkH3jBAe74ife6fJJu6k6q8=/2121x1414/filters:fill(auto,1)/Red-eared-sliders-GettyImages-617946009-58fae8835f9b581d59a5bab6.jpg
|
||||
http://assets.worldwildlife.org/photos/167/images/original/MID_225023-circle-hawksbill-turtle.jpg?1345565600
|
||||
https://seaturtles.org/wp-content/uploads/2013/11/GRN-honuAnitaWintner2.jpg
|
||||
https://images2.minutemediacdn.com/image/upload/c_crop,h_2549,w_4536,x_0,y_237/v1560186367/shape/mentalfloss/istock-687398754.jpg?itok=QsiF5yHP
|
||||
https://c402277.ssl.cf1.rackcdn.com/photos/13028/images/story_full_width/seaturtle_spring2017.jpg?1485359391
|
||||
https://i2.wp.com/rangerrick.org/wp-content/uploads/2018/03/Turtle-Tale-RR-Jr-June-July-2017.jpg?fit=1156%2C650&ssl=1
|
||||
https://boyslifeorg.files.wordpress.com/2019/07/greenseaturtle.jpg
|
|
@ -1,23 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
|
||||
<Version Condition=" '$(VersionSuffix)' != '' ">$(VersionSuffix)</Version>
|
||||
<Version Condition=" '$(VersionSuffix)' == '' ">0.0.0-DEV</Version>
|
||||
<RootNamespace>Geekbot.Commands</RootNamespace>
|
||||
<AssemblyName>Geekbot.Commands</AssemblyName>
|
||||
<NoWarn>NU1701</NoWarn>
|
||||
<NoWarn>CS8618</NoWarn>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||
<OutputType>Library</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core\Core.csproj" />
|
||||
<ProjectReference Include="..\Interactions\Interactions.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -1,103 +0,0 @@
|
|||
using System.Drawing;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Database.Models;
|
||||
using Geekbot.Interactions.Embed;
|
||||
using Geekbot.Interactions.Resolved;
|
||||
using Localization = Geekbot.Core.Localization;
|
||||
|
||||
namespace Geekbot.Commands.Karma;
|
||||
|
||||
public class Karma
|
||||
{
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly long _guildId;
|
||||
|
||||
public Karma(DatabaseContext database, long guildId)
|
||||
{
|
||||
_database = database;
|
||||
_guildId = guildId;
|
||||
}
|
||||
|
||||
public async Task<Embed> ChangeKarma(User author, User targetUser, KarmaChange change)
|
||||
{
|
||||
// Get the user
|
||||
var authorRecord = await GetUser(long.Parse(author.Id));
|
||||
|
||||
// Check if the user can change karma
|
||||
if (targetUser.Id == author.Id)
|
||||
{
|
||||
var message = change switch
|
||||
{
|
||||
KarmaChange.Up => Localization.Karma.CannotChangeOwnUp,
|
||||
KarmaChange.Same => Localization.Karma.CannotChangeOwnSame,
|
||||
KarmaChange.Down => Localization.Karma.CannotChangeOwnDown,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(change), change, null)
|
||||
};
|
||||
return Embed.ErrorEmbed(string.Format(message, author.Username));
|
||||
}
|
||||
|
||||
var timeoutMinutes = 3;
|
||||
if (authorRecord.TimeOut.AddMinutes(timeoutMinutes) > DateTimeOffset.Now.ToUniversalTime())
|
||||
{
|
||||
var remaining = authorRecord.TimeOut.AddMinutes(timeoutMinutes) - DateTimeOffset.Now.ToUniversalTime();
|
||||
var formatedWaitTime = DateLocalization.FormatDateTimeAsRemaining(remaining);
|
||||
return Embed.ErrorEmbed(string.Format(Localization.Karma.WaitUntill, author.Username, formatedWaitTime));
|
||||
}
|
||||
|
||||
// Get the values for the change direction
|
||||
var (title, amount) = change switch
|
||||
{
|
||||
KarmaChange.Up => (Localization.Karma.Increased, 1),
|
||||
KarmaChange.Same => (Localization.Karma.Neutral, 0),
|
||||
KarmaChange.Down => (Localization.Karma.Decreased, -1),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(change), change, null)
|
||||
};
|
||||
|
||||
// Change it
|
||||
var targetUserRecord = await GetUser(long.Parse(targetUser.Id));
|
||||
targetUserRecord.Karma += amount;
|
||||
_database.Karma.Update(targetUserRecord);
|
||||
|
||||
authorRecord.TimeOut = DateTimeOffset.Now.ToUniversalTime();
|
||||
_database.Karma.Update(authorRecord);
|
||||
|
||||
await _database.SaveChangesAsync();
|
||||
|
||||
// Respond
|
||||
var eb = new Embed()
|
||||
{
|
||||
Author = new ()
|
||||
{
|
||||
Name = targetUser.Username,
|
||||
IconUrl = targetUser.GetAvatarUrl()
|
||||
},
|
||||
Title = title,
|
||||
};
|
||||
eb.SetColor(Color.PaleGreen);
|
||||
eb.AddInlineField(Localization.Karma.By, author.Username);
|
||||
eb.AddInlineField(Localization.Karma.Amount, amount.ToString());
|
||||
eb.AddInlineField(Localization.Karma.Current, targetUserRecord.Karma.ToString());
|
||||
return eb;
|
||||
}
|
||||
|
||||
private async Task<KarmaModel> GetUser(long userId)
|
||||
{
|
||||
var user = _database.Karma.FirstOrDefault(u => u.GuildId.Equals(_guildId) && u.UserId.Equals(userId)) ?? await CreateNewRow(userId);
|
||||
return user;
|
||||
}
|
||||
|
||||
private async Task<KarmaModel> CreateNewRow(long userId)
|
||||
{
|
||||
var user = new KarmaModel()
|
||||
{
|
||||
GuildId = _guildId,
|
||||
UserId = userId,
|
||||
Karma = 0,
|
||||
TimeOut = DateTimeOffset.MinValue.ToUniversalTime()
|
||||
};
|
||||
var newUser = _database.Karma.Add(user).Entity;
|
||||
await _database.SaveChangesAsync();
|
||||
return newUser;
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
namespace Geekbot.Commands.Karma;
|
||||
|
||||
public enum KarmaChange
|
||||
{
|
||||
Up,
|
||||
Same,
|
||||
Down
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue