migrate old Repo
This commit is contained in:
commit
39755c7cdd
41 changed files with 4850 additions and 0 deletions
122
.gitignore
vendored
Normal file
122
.gitignore
vendored
Normal file
|
@ -0,0 +1,122 @@
|
|||
# ---> Gradle
|
||||
.gradle
|
||||
/build/
|
||||
|
||||
# Ignore Gradle GUI config
|
||||
gradle-app.setting
|
||||
|
||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||
!gradle-wrapper.jar
|
||||
|
||||
# Cache of project
|
||||
.gradletasknamecache
|
||||
|
||||
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
|
||||
# gradle/wrapper/gradle-wrapper.properties
|
||||
|
||||
# ---> JetBrains
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff:
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/dictionaries
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.xml
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
/out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# ---> Eclipse
|
||||
|
||||
.metadata
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
.recommenders
|
||||
|
||||
# Eclipse Core
|
||||
.project
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# PyDev specific (Python IDE for Eclipse)
|
||||
*.pydevproject
|
||||
|
||||
# CDT-specific (C/C++ Development Tooling)
|
||||
.cproject
|
||||
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
|
||||
# Java annotation processor (APT)
|
||||
.factorypath
|
||||
|
||||
# PDT-specific (PHP Development Tools)
|
||||
.buildpath
|
||||
|
||||
# sbteclipse plugin
|
||||
.target
|
||||
|
||||
# Tern plugin
|
||||
.tern-project
|
||||
|
||||
# TeXlipse plugin
|
||||
.texlipse
|
||||
|
||||
# STS (Spring Tool Suite)
|
||||
.springBeans
|
||||
|
||||
# Code Recommenders
|
||||
.recommenders/
|
||||
|
||||
# Scala IDE specific (Scala & Java development for Eclipse)
|
||||
.cache-main
|
||||
.scala_dependencies
|
||||
.worksheet
|
||||
|
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
# Default ignored files
|
||||
/workspace.xml
|
1
.idea/.name
Normal file
1
.idea/.name
Normal file
|
@ -0,0 +1 @@
|
|||
MittweidaForFuture2
|
20
.idea/jarRepositories.xml
Normal file
20
.idea/jarRepositories.xml
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="BintrayJCenter" />
|
||||
<option name="name" value="BintrayJCenter" />
|
||||
<option name="url" value="https://jcenter.bintray.com/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
8
.idea/misc.xml
Normal file
8
.idea/misc.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="JavaScriptSettings">
|
||||
<option name="languageLevel" value="ES6" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="12" project-jdk-type="JavaSDK" />
|
||||
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
50
build.gradle
Normal file
50
build.gradle
Normal file
|
@ -0,0 +1,50 @@
|
|||
plugins {
|
||||
id 'java'
|
||||
id 'application'
|
||||
}
|
||||
|
||||
group 'BOTS'
|
||||
version '4.1'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
mainClassName = 'Main'
|
||||
|
||||
|
||||
def jsonsimpleVersion = '1.1.1'
|
||||
def telegramBotsVersion = '4.3.1'
|
||||
def self4JVersion = '1.7.28'
|
||||
def log4jVersion = '2.12.1'
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: jsonsimpleVersion
|
||||
compile group: 'org.telegram', name: 'telegrambots', version: telegramBotsVersion
|
||||
compile group: 'org.slf4j', name: 'slf4j-api', version: self4JVersion
|
||||
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: self4JVersion
|
||||
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: log4jVersion
|
||||
}
|
||||
apply plugin: 'java'
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
|
||||
//create a single Jar with all dependencies
|
||||
task fatJar(type: Jar) {
|
||||
|
||||
manifest {
|
||||
attributes 'BOT': 'MittweidaForFuture2',
|
||||
'Implementation-Version': version,
|
||||
'Main-Class': mainClassName
|
||||
}
|
||||
|
||||
baseName = project.name + '-all'
|
||||
from {
|
||||
configurations
|
||||
.compile
|
||||
.findAll { !it.name.endsWith('pom') }
|
||||
.collect { it.isDirectory() ? it : zipTree(it) }
|
||||
}
|
||||
with jar
|
||||
}
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
#Fri Aug 23 13:14:43 CEST 2019
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
|
172
gradlew
vendored
Normal file
172
gradlew
vendored
Normal file
|
@ -0,0 +1,172 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a old.user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
84
gradlew.bat
vendored
Normal file
84
gradlew.bat
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
18
resources/log4j.properties
Normal file
18
resources/log4j.properties
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Root logger option
|
||||
log4j.rootLogger=TRACE, stdout
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Target=System.out
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd'T'HH:mm:ss.SSS} %-5p [%c] - %m%n
|
||||
|
||||
# Direct log messages to a log file
|
||||
log4j.appender.file=org.apache.log4j.RollingFileAppender
|
||||
log4j.appender.file.File=./logs/logging.log
|
||||
log4j.appender.file.MaxFileSize=10MB
|
||||
log4j.appender.file.MaxBackupIndex=10
|
||||
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
||||
|
||||
# exclude JDA DEBUG
|
||||
#log4j.logger.net.dv8tion.jda=INFO, stdout
|
||||
#log4j.additivity.net.dv8tion.jda=false
|
17
resources/self4j.properties
Normal file
17
resources/self4j.properties
Normal file
|
@ -0,0 +1,17 @@
|
|||
log4j.rootLogger=ALL, stdout, R
|
||||
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
|
||||
# Pattern to output the caller's file name and line number.
|
||||
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
|
||||
|
||||
log4j.appender.R=org.apache.log4j.RollingFileAppender
|
||||
log4j.appender.R.File=this.log
|
||||
|
||||
log4j.appender.R.MaxFileSize=10MB
|
||||
# Keep one backup file
|
||||
log4j.appender.R.MaxBackupIndex=1
|
||||
|
||||
log4j.appender.R.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
|
5
resources/simplelogger.properties
Normal file
5
resources/simplelogger.properties
Normal file
|
@ -0,0 +1,5 @@
|
|||
org.slf4j.simpleLogger.defaultLogLevel = debug
|
||||
org.slf4j.simpleLogger.showDateTime = true
|
||||
org.slf4j.simpleLogger.dateTimeFormat = yyyy-MM-dd HH:mm:ss
|
||||
org.slf4j.simpleLogger.showThreadName = false
|
||||
org.slf4j.simpleLogger.levelInBrackets = true
|
2
settings.gradle
Normal file
2
settings.gradle
Normal file
|
@ -0,0 +1,2 @@
|
|||
rootProject.name = 'MittweidaForFuture2'
|
||||
|
176
src/main/java/CORE/Core.java
Normal file
176
src/main/java/CORE/Core.java
Normal file
|
@ -0,0 +1,176 @@
|
|||
package CORE;
|
||||
|
||||
import Manager.ChatManager;
|
||||
import Manager.UserManager;
|
||||
import Modules.*;
|
||||
import Modules.Module;
|
||||
import Utility.User.MyUser;
|
||||
import Utility.jsonUtils;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
|
||||
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
||||
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageText;
|
||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Core extends TelegramLongPollingBot {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(Core.class);
|
||||
|
||||
public static final int MUTETIMER = 60; //MINUTES
|
||||
public static final long GUEST_TIME = 1000 * 60 * 60; // 1H
|
||||
public static final int SLOWMODETIMER = 35; //seconds
|
||||
|
||||
public static long ADMIN_CHAT_ID;
|
||||
public static JSONArray OPEN_CHATS;
|
||||
public static String GUEST_CHAT_JOIN_LINK ;
|
||||
public static String TEAM_NAME;
|
||||
public static boolean NO_BOT_RIGHTS;
|
||||
|
||||
private static String BOT_TOKEN;
|
||||
private static String BOT_USERNAME;
|
||||
|
||||
public static HashMap<Long, MyUser> userMap;
|
||||
|
||||
|
||||
private List<Module> modules;
|
||||
private Map<Long, MyUser> open_requests;
|
||||
private Set<Long> watchingChats;
|
||||
|
||||
public Core(){
|
||||
|
||||
log.info("load config");
|
||||
JSONObject config = (JSONObject) jsonUtils.loadJson("config.json").get(0);
|
||||
|
||||
ADMIN_CHAT_ID = (long) config.get("masterUserId");
|
||||
OPEN_CHATS = (JSONArray) config.get("openChats");
|
||||
GUEST_CHAT_JOIN_LINK = (String) config.get("guestChatJoinLink");
|
||||
TEAM_NAME = (String) config.get("teamname");
|
||||
NO_BOT_RIGHTS = (Boolean) config.get("no_bot_rights_option");
|
||||
BOT_TOKEN = (String) config.get("botToken");
|
||||
BOT_USERNAME = (String) config.get("botUserName");
|
||||
|
||||
userMap = new HashMap<>();
|
||||
open_requests = new HashMap<>();
|
||||
watchingChats = ChatManager.loadWatch();
|
||||
|
||||
UserManager.loadUserList();
|
||||
|
||||
log.info("init all modules");
|
||||
modules = new ArrayList<>();
|
||||
modules.add(new AdminMenue(this));
|
||||
modules.add(new BasicModule(this));
|
||||
modules.add(new ModCommands(this));
|
||||
modules.add(new SlowMode(this));
|
||||
modules.add(new UserMenue(this));
|
||||
modules.add(new Welcome(this));
|
||||
log.info("done");
|
||||
|
||||
}
|
||||
|
||||
/*----------Help Methods to send and edit messages----------*/
|
||||
|
||||
public void send_message(SendMessage message) {
|
||||
log.debug("Send message " + message);
|
||||
try {
|
||||
execute(message);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void edit_message(EditMessageText message) {
|
||||
log.debug("Send edit message " + message);
|
||||
try {
|
||||
execute(message);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void send_message_toadmins(SendMessage message) {
|
||||
log.debug("Send message to admins" + message);
|
||||
List<MyUser> admin_list = UserManager.buildAdminList();
|
||||
|
||||
for (MyUser admin : admin_list) {
|
||||
long admin_id = admin.getId();
|
||||
message.setChatId(admin_id);
|
||||
send_message(message);
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------- Other Mehtods ------------------------------------*/
|
||||
|
||||
public static String getUserAsMention(User user){
|
||||
|
||||
if (user instanceof MyUser)
|
||||
return ((MyUser)user).getUserName();
|
||||
|
||||
String userName;
|
||||
|
||||
if (user.getUserName() != null){
|
||||
userName = user.getUserName();
|
||||
} else if (user.getFirstName() != null){
|
||||
userName = user.getFirstName();
|
||||
} else if (user.getLastName() != null){
|
||||
userName = user.getLastName();
|
||||
} else {
|
||||
userName = "StealthUser";
|
||||
}
|
||||
|
||||
userName = "<a href=\"tg://user?id=" + user.getId() + "\">" + userName + "</a>";
|
||||
|
||||
return userName;
|
||||
}
|
||||
|
||||
public HashMap<Long, MyUser> getUserMap() {
|
||||
return userMap;
|
||||
}
|
||||
|
||||
public Map<Long, MyUser> getOpen_requests() {
|
||||
return open_requests;
|
||||
}
|
||||
|
||||
public Set<Long> getWatchingChats() {
|
||||
return watchingChats;
|
||||
}
|
||||
|
||||
public void saveWhatchingChats(){
|
||||
ChatManager.saveWatch(watchingChats);
|
||||
}
|
||||
|
||||
/*-------------------------------- BOT FUNCTIONS -------------------------------------------*/
|
||||
|
||||
@Override
|
||||
public void onUpdateReceived(Update update) {
|
||||
|
||||
log.trace("Got an Update: " + update.toString());
|
||||
|
||||
//Check if user is blocked
|
||||
if (update.hasMessage() && UserManager.checkBlacklist(update.getMessage().getFrom().getId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Module x : modules)
|
||||
x.execute(update);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBotUsername() {
|
||||
return BOT_USERNAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBotToken() {
|
||||
return BOT_TOKEN;
|
||||
}
|
||||
}
|
29
src/main/java/Main.java
Normal file
29
src/main/java/Main.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
import CORE.Core;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.telegram.telegrambots.ApiContextInitializer;
|
||||
import org.telegram.telegrambots.meta.TelegramBotsApi;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
||||
|
||||
public class Main {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(Main.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
log.info("Startup of bot");
|
||||
|
||||
ApiContextInitializer.init();
|
||||
|
||||
TelegramBotsApi botsApi = new TelegramBotsApi();
|
||||
|
||||
try {
|
||||
botsApi.registerBot(new Core());
|
||||
} catch (TelegramApiException e) {
|
||||
log.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
364
src/main/java/Manager/ChatManager.java
Normal file
364
src/main/java/Manager/ChatManager.java
Normal file
|
@ -0,0 +1,364 @@
|
|||
package Manager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import Utility.User.UserPermission;
|
||||
import Utility.chat.Chat;
|
||||
import Utility.chat.ChatCategory;
|
||||
import Utility.jsonUtils;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ChatManager {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(ChatManager.class);
|
||||
|
||||
private static final String CHATS_FILENAME = "chats.json";
|
||||
|
||||
/**
|
||||
* Load All chats to look ak
|
||||
* @return list of Chats
|
||||
*/
|
||||
public static Set<Long> loadWatch(){
|
||||
log.debug("Load WhatchChats");
|
||||
|
||||
Set<Long> ret = new HashSet<>();
|
||||
for (Object o : jsonUtils.loadJson("WatchChats.json")){
|
||||
JSONObject x = (JSONObject) o;
|
||||
|
||||
ret.add(Long.parseLong(x.get("ID").toString()));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safe list of chats to look at
|
||||
* @param list list of chats to save
|
||||
*/
|
||||
public static void saveWatch(Set<Long> list){
|
||||
log.debug("Save WhatchChats");
|
||||
|
||||
JSONArray save = new JSONArray();
|
||||
|
||||
for (long x : list){
|
||||
JSONObject tmp = new JSONObject();
|
||||
tmp.put("ID", Long.toString(x));
|
||||
save.add(tmp);
|
||||
}
|
||||
|
||||
jsonUtils.saveJson(save, "WatchChats.json");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new Chat Category
|
||||
* @param category new Category
|
||||
*/
|
||||
public static void addCategory(ChatCategory category) {
|
||||
log.info("Adding Utility.chat category " + category.getName());
|
||||
|
||||
JSONArray categories = jsonUtils.loadJson(CHATS_FILENAME);
|
||||
|
||||
//Check if the uid is actually unique
|
||||
if (checkCategoryUID(category.getUid())) {
|
||||
log.debug("no unique Chat ID");
|
||||
return;
|
||||
}
|
||||
|
||||
JSONObject newCategory = new JSONObject();
|
||||
newCategory.put("uid", category.getUid());
|
||||
newCategory.put("name", category.getName());
|
||||
newCategory.put("chats", new JSONArray());
|
||||
|
||||
categories.add(newCategory);
|
||||
|
||||
jsonUtils.saveJson(categories, CHATS_FILENAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a List with all Chat Categories
|
||||
* @return List of ChatCategories
|
||||
*/
|
||||
public static List<ChatCategory> loadCategories() {
|
||||
log.debug("Loading chat categories from file");
|
||||
|
||||
JSONArray categoriesJson = jsonUtils.loadJson(CHATS_FILENAME);
|
||||
List<ChatCategory> categories = new ArrayList<>();
|
||||
|
||||
for (Object o : categoriesJson) {
|
||||
JSONObject category = (JSONObject) o;
|
||||
long uid = (long) category.get("uid");
|
||||
|
||||
categories.add(loadCategory(uid));
|
||||
}
|
||||
|
||||
return categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load singe Chat Category by ID
|
||||
* @param uid id of Categoriy
|
||||
* @return ChatCategory
|
||||
*/
|
||||
public static ChatCategory loadCategory(long uid) {
|
||||
log.debug("Loading chat category by uid " + uid);
|
||||
JSONArray categories = jsonUtils.loadJson(CHATS_FILENAME);
|
||||
|
||||
for (Object o : categories) {
|
||||
JSONObject category = (JSONObject) o;
|
||||
long searchUid = (long) category.get("uid");
|
||||
|
||||
if (searchUid == uid) {
|
||||
String name = (String) category.get("name");
|
||||
JSONArray chatsJson = (JSONArray) category.get("chats");
|
||||
List<Chat> chats = new ArrayList<>();
|
||||
|
||||
for (Object c : chatsJson) {
|
||||
JSONObject chatJson = (JSONObject) c;
|
||||
long chatUid = (long) chatJson.get("uid");
|
||||
String chatName = (String) chatJson.get("name");
|
||||
String chatUrl = (String) chatJson.get("url");
|
||||
String permissionJson = (String) chatJson.get("permissionNeeded");
|
||||
UserPermission permissionNeeded = UserPermission.valueOf(permissionJson);
|
||||
|
||||
chats.add(new Chat(chatUid, chatName, chatUrl, permissionNeeded));
|
||||
}
|
||||
|
||||
ChatCategory found = new ChatCategory(uid, name);
|
||||
found.setChatList(chats);
|
||||
|
||||
return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete existing Category
|
||||
* @param uid id of Category to delete
|
||||
*/
|
||||
public static void deleteCategory(long uid) {
|
||||
log.info("delete Category: " + uid);
|
||||
|
||||
JSONArray categories = jsonUtils.loadJson(CHATS_FILENAME);
|
||||
|
||||
for (Object o : categories) {
|
||||
JSONObject category = (JSONObject)o;
|
||||
long searchUid = (Long) category.get("uid");
|
||||
|
||||
if (searchUid == uid) {
|
||||
categories.remove(o);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
jsonUtils.saveJson(categories, CHATS_FILENAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a ChatCategory uid already exists
|
||||
* @param uid ID to check
|
||||
* @return boolean true if exists
|
||||
*/
|
||||
public static boolean checkCategoryUID(long uid) {
|
||||
log.debug("Checking if Utility.chat category " + uid + " already exists");
|
||||
JSONArray categories = jsonUtils.loadJson(CHATS_FILENAME);
|
||||
|
||||
for (Object o : categories) {
|
||||
JSONObject category = (JSONObject) o;
|
||||
long searchUid = (long) category.get("uid");
|
||||
|
||||
if (uid == searchUid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a Chat uid already exists
|
||||
* @param uid ID to check
|
||||
* @return boolean true if exists
|
||||
*/
|
||||
public static boolean checkChatUID(long uid) {
|
||||
JSONArray categories = jsonUtils.loadJson(CHATS_FILENAME);
|
||||
|
||||
for (Object o : categories) {
|
||||
JSONObject category = (JSONObject)o;
|
||||
JSONArray chats = (JSONArray)category.get("chats");
|
||||
|
||||
for (Object c : chats) {
|
||||
JSONObject chat = (JSONObject) c;
|
||||
long chatUid = (long) chat.get("uid");
|
||||
|
||||
if (uid == chatUid)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get biggest chatCategory Uid
|
||||
* @return Greatest UID
|
||||
*/
|
||||
public static long getBiggestChatCategoryUid() {
|
||||
log.debug("Get biggest Utility.chat category uid");
|
||||
JSONArray categories = jsonUtils.loadJson(CHATS_FILENAME);
|
||||
long biggestUid = 0;
|
||||
|
||||
for (Object o : categories) {
|
||||
JSONObject category = (JSONObject) o;
|
||||
long uid = (long) category.get("uid");
|
||||
if (uid > biggestUid) {
|
||||
biggestUid = uid;
|
||||
}
|
||||
}
|
||||
|
||||
return biggestUid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Chat into Category
|
||||
* @param chat Chat to save
|
||||
* @param categoryUid Category to save chat into
|
||||
*/
|
||||
public static void saveChat(Chat chat, long categoryUid)
|
||||
{
|
||||
JSONArray categories = jsonUtils.loadJson(CHATS_FILENAME);
|
||||
|
||||
//search for Category
|
||||
for (Object o : categories) {
|
||||
JSONObject category = (JSONObject)o;
|
||||
long searchCategoryUid = (Long) category.get("uid");
|
||||
|
||||
//If found
|
||||
if (searchCategoryUid == categoryUid) {
|
||||
|
||||
JSONArray chats = (JSONArray)category.get("chats");
|
||||
|
||||
//search if chat already exist
|
||||
for (Object c : chats) {
|
||||
JSONObject searchChat = (JSONObject)c;
|
||||
long searchChatUid = (Long) searchChat.get("uid");
|
||||
|
||||
//if chat already exists, delete it
|
||||
if (searchChatUid == chat.getUid()) {
|
||||
chats.remove(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//save chat
|
||||
JSONObject chatJson = new JSONObject();
|
||||
chatJson.put("uid", chat.getUid());
|
||||
chatJson.put("name", chat.getName());
|
||||
chatJson.put("url", chat.getUrl());
|
||||
chatJson.put("permissionNeeded", chat.getPermissionNeeded().toString());
|
||||
chats.add(chatJson);
|
||||
}
|
||||
}
|
||||
jsonUtils.saveJson(categories, CHATS_FILENAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads specific chat out of specific category
|
||||
* @param chatUid chat id to load
|
||||
* @param categoryUid category id where chat is located
|
||||
* @return Chat
|
||||
*/
|
||||
public static Chat loadChatFromCategory(long chatUid, long categoryUid)
|
||||
{
|
||||
JSONArray categories = jsonUtils.loadJson(CHATS_FILENAME);
|
||||
|
||||
for (Object o : categories) {
|
||||
JSONObject category = (JSONObject)o;
|
||||
long searchCategoryUid = (Long) category.get("uid");
|
||||
|
||||
if (searchCategoryUid == categoryUid) {
|
||||
JSONArray chats = (JSONArray)category.get("chats");
|
||||
|
||||
for (Object c : chats) {
|
||||
JSONObject chat = (JSONObject)c;
|
||||
long searchChatUid = (Long) chat.get("uid");
|
||||
|
||||
if (searchChatUid == chatUid) {
|
||||
String name = (String)chat.get("name");
|
||||
String url = (String)chat.get("url");
|
||||
String permissionString = (String)chat.get("permissionNeeded");
|
||||
UserPermission permissionNeeded = UserPermission.valueOf(permissionString);
|
||||
|
||||
return new Chat(chatUid, name, url, permissionNeeded);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Chat
|
||||
* @param chatUid ID of chat to delete
|
||||
*/
|
||||
public static void deleteChat(long chatUid)
|
||||
{
|
||||
JSONArray categories = jsonUtils.loadJson(CHATS_FILENAME);
|
||||
|
||||
for (Object o : categories) {
|
||||
JSONObject category = (JSONObject)o;
|
||||
JSONArray chats = (JSONArray)category.get("chats");
|
||||
|
||||
for (Object c : chats) {
|
||||
JSONObject searchChat = (JSONObject)c;
|
||||
long searchChatUid = (Long) searchChat.get("uid");
|
||||
|
||||
if (searchChatUid == chatUid) {
|
||||
chats.remove(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
category.put("chats", chats);
|
||||
}
|
||||
jsonUtils.saveJson(categories, CHATS_FILENAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change UID of a Chat
|
||||
* @param chat new Chat
|
||||
* @param categoryUid Category ID where chat is located
|
||||
* @param oldUid ID of Chat to change
|
||||
*/
|
||||
public static void changeUid(Chat chat, long categoryUid, long oldUid)
|
||||
{
|
||||
JSONArray categories = jsonUtils.loadJson(CHATS_FILENAME);
|
||||
|
||||
for (Object o : categories) {
|
||||
|
||||
JSONObject category = (JSONObject)o;
|
||||
|
||||
long searchCategoryUid = (Long) category.get("uid");
|
||||
|
||||
if (searchCategoryUid == categoryUid) {
|
||||
JSONArray chats = (JSONArray)category.get("chats");
|
||||
|
||||
for (Object c : chats) {
|
||||
|
||||
JSONObject searchChat = (JSONObject)c;
|
||||
long searchChatUid = (Long) searchChat.get("uid");
|
||||
|
||||
if (searchChatUid == oldUid) {
|
||||
searchChat.put("uid", chat.getUid());
|
||||
searchChat.put("name", chat.getName());
|
||||
searchChat.put("url", chat.getUrl());
|
||||
searchChat.put("permissionNeeded", chat.getPermissionNeeded().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
jsonUtils.saveJson(categories, CHATS_FILENAME);
|
||||
}
|
||||
}
|
597
src/main/java/Manager/UserManager.java
Normal file
597
src/main/java/Manager/UserManager.java
Normal file
|
@ -0,0 +1,597 @@
|
|||
package Manager;
|
||||
|
||||
import CORE.Core;
|
||||
import Utility.User.GuestHandle;
|
||||
import Utility.User.MyUser;
|
||||
import Utility.User.Roles;
|
||||
import Utility.User.UserPermission;
|
||||
import Utility.jsonUtils;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.KickChatMember;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.UnbanChatMember;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
|
||||
public class UserManager {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(UserManager.class);
|
||||
|
||||
private static final String WHITELIST_FILENAME = "whitelist.json";
|
||||
private static final String BLOCKLIST_FILENAME = "blocklist.json";
|
||||
|
||||
/**
|
||||
* Put User in Whitelist with specific role
|
||||
* @param user user to add
|
||||
*/
|
||||
public static void whitelistUser(MyUser user, Core core) {
|
||||
log.info("Adding whitelist " + Core.getUserAsMention(user) + " - " + user.getId());
|
||||
|
||||
//Check if user is not already on whitelist
|
||||
if (checkWhitelist(user.getId())) {
|
||||
log.error("Adding whitelist error - already on whitelist");
|
||||
return;
|
||||
}
|
||||
|
||||
//Check if user is not already on blocklist
|
||||
if (checkBlacklist(user.getId())) {
|
||||
log.error("Adding whitelist error - already on blacklist");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* ROLES
|
||||
* Admin
|
||||
* User
|
||||
* Guest
|
||||
*/
|
||||
|
||||
// Save user to whitelist
|
||||
JSONObject new_user = new JSONObject();
|
||||
new_user.put("id", user.getId());
|
||||
new_user.put("user_name", Core.getUserAsMention(user));
|
||||
new_user.put("role", user.getRole().name());
|
||||
new_user.put("permissions", new JSONArray());
|
||||
|
||||
JSONArray whitelist = jsonUtils.loadJson(WHITELIST_FILENAME);
|
||||
whitelist.add(new_user);
|
||||
jsonUtils.saveJson(whitelist, WHITELIST_FILENAME);
|
||||
|
||||
// Update Usermap
|
||||
Core.userMap.put((long)user.getId(), user);
|
||||
|
||||
//Start Guesttimer
|
||||
if (user.getRole() == Roles.GUEST)
|
||||
new Timer().schedule(new GuestHandle(core, user.getId()), Core.GUEST_TIME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change user
|
||||
* @param user user to change
|
||||
*/
|
||||
public static void changeUser(MyUser user, Core core) {
|
||||
log.info("Changing user" + Core.getUserAsMention(user) + " - " + user.getId());
|
||||
|
||||
JSONArray whitelist = jsonUtils.loadJson(WHITELIST_FILENAME);
|
||||
|
||||
if (!checkWhitelist(user.getId())){
|
||||
//TODO ERROR
|
||||
log.debug("User not in whitelist!");
|
||||
return;
|
||||
}
|
||||
|
||||
//Find user entry
|
||||
for (Object o : whitelist) {
|
||||
|
||||
JSONObject search = (JSONObject) o;
|
||||
long searchId = (long) search.get("id");
|
||||
|
||||
//if user entry found:
|
||||
if (searchId == user.getId()) {
|
||||
//remove old entry
|
||||
whitelist.remove(o);
|
||||
|
||||
//add user with new Role
|
||||
JSONObject changed = new JSONObject();
|
||||
|
||||
changed.put("id", user.getId());
|
||||
changed.put("user_name", Core.getUserAsMention(user));
|
||||
changed.put("role", user.getRole().name());
|
||||
|
||||
JSONArray permissions = new JSONArray();
|
||||
|
||||
if (user.getPermission() != null && user.getPermission().size() > 0) {
|
||||
for (UserPermission x : user.getPermission())
|
||||
permissions.add(x.name());
|
||||
}
|
||||
|
||||
changed.put("permissions", permissions);
|
||||
|
||||
whitelist.add(changed);
|
||||
|
||||
//Start Guesttimer
|
||||
if (user.getRole() == Roles.GUEST)
|
||||
new Timer().schedule(new GuestHandle(core, user.getId()), Core.GUEST_TIME);
|
||||
|
||||
// Update Usermap
|
||||
Core.userMap.put((long)user.getId(), user);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
jsonUtils.saveJson(whitelist, WHITELIST_FILENAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove user from Whitelist and write to Blacklist
|
||||
* @param user user to block
|
||||
*/
|
||||
public static void blockUser(User user, Core core) {
|
||||
log.info("Adding Blacklist " + Core.getUserAsMention(user) + " - " + user.getId());
|
||||
|
||||
//Load id and username
|
||||
long id = user.getId();
|
||||
|
||||
if (checkWhitelist(user.getId())) {
|
||||
JSONArray whitelist = jsonUtils.loadJson(WHITELIST_FILENAME);
|
||||
//Remove user From Whitelist
|
||||
for (Object o : whitelist) {
|
||||
|
||||
JSONObject userjson = (JSONObject) o;
|
||||
long userjson_id = (long) userjson.get("id");
|
||||
|
||||
//if user id is matching remove entry
|
||||
if (userjson_id == id) {
|
||||
whitelist.remove(o);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//save new list
|
||||
jsonUtils.saveJson(whitelist, WHITELIST_FILENAME);
|
||||
|
||||
//Block in chats
|
||||
//kick user from all chats
|
||||
for (long x : core.getWatchingChats()) {
|
||||
KickChatMember kick = new KickChatMember()
|
||||
.setChatId(x)
|
||||
.setUserId(user.getId());
|
||||
try {
|
||||
kick.validate();
|
||||
core.execute(kick);
|
||||
} catch (TelegramApiException e) {
|
||||
log.error(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JSONArray blocklist = jsonUtils.loadJson(BLOCKLIST_FILENAME);
|
||||
|
||||
// Save user to blocklist
|
||||
JSONObject new_user = new JSONObject();
|
||||
new_user.put("id", id);
|
||||
new_user.put("user_name", Core.getUserAsMention(user));
|
||||
blocklist.add(new_user);
|
||||
|
||||
jsonUtils.saveJson(blocklist, BLOCKLIST_FILENAME);
|
||||
|
||||
// Update Usermap
|
||||
Core.userMap.remove((long)user.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove user from Blacklist
|
||||
* @param userId user id to remove
|
||||
*/
|
||||
public static void unblock(long userId, Core core) {
|
||||
|
||||
log.info("Remove from Blocklist " + userId);
|
||||
|
||||
JSONArray blocklist = jsonUtils.loadJson(BLOCKLIST_FILENAME);
|
||||
|
||||
//search user entry
|
||||
for (Object o : blocklist) {
|
||||
JSONObject userjson = (JSONObject) o;
|
||||
|
||||
long user_id = (long) userjson.get("id");
|
||||
|
||||
//remove if id is equal
|
||||
if (user_id == userId) {
|
||||
blocklist.remove(o);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//safe new blocklist
|
||||
jsonUtils.saveJson(blocklist, BLOCKLIST_FILENAME);
|
||||
|
||||
//unBlock in chats
|
||||
//kick user from all chats
|
||||
for (long x : core.getWatchingChats()) {
|
||||
UnbanChatMember unban = new UnbanChatMember()
|
||||
.setChatId(x)
|
||||
.setUserId((int) userId);
|
||||
try {
|
||||
unban.validate();
|
||||
core.execute(unban);
|
||||
} catch (TelegramApiException e) {
|
||||
log.error(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove user From Whitelist
|
||||
* @param userID user id to remove
|
||||
*/
|
||||
public static void removeUser(long userID){
|
||||
log.info("Remove from Whitelist " + userID);
|
||||
|
||||
// Update Usermap
|
||||
Core.userMap.remove(userID);
|
||||
|
||||
JSONArray whitelist = jsonUtils.loadJson(WHITELIST_FILENAME);
|
||||
|
||||
//search User
|
||||
for (Object o : whitelist) {
|
||||
|
||||
JSONObject search = (JSONObject) o;
|
||||
long searchId = (long) search.get("id");
|
||||
|
||||
//remove if id is equal
|
||||
if (searchId == userID) {
|
||||
whitelist.remove(o);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
jsonUtils.saveJson(whitelist, WHITELIST_FILENAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is Admin
|
||||
* @param userId user id to check
|
||||
* @return boolean true if admin
|
||||
*/
|
||||
public static boolean checkAdmin(long userId) {
|
||||
log.debug("Checking if user " + userId + " is admin");
|
||||
|
||||
//first lookup hashmap
|
||||
if (Core.userMap.containsKey(userId))
|
||||
return Core.userMap.get(userId).getRole() == Roles.ADMIN;
|
||||
|
||||
JSONArray whitelist = jsonUtils.loadJson(WHITELIST_FILENAME);
|
||||
|
||||
//search userid
|
||||
for (Object o : whitelist) {
|
||||
|
||||
JSONObject user = (JSONObject) o;
|
||||
long user_id = (long) user.get("id");
|
||||
if (user_id == userId) {
|
||||
String role = (String) user.get("role");
|
||||
if (role.equalsIgnoreCase(Roles.ADMIN.name())){
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all Admins out of whitelist
|
||||
* @return Arraylist out of admins
|
||||
*/
|
||||
public static ArrayList<MyUser> buildAdminList() {
|
||||
|
||||
log.debug("Build admin list");
|
||||
ArrayList<MyUser> admins = new ArrayList<>();
|
||||
|
||||
for (long key : Core.userMap.keySet()){
|
||||
if (Core.userMap.get(key).getRole() == Roles.ADMIN)
|
||||
admins.add(Core.userMap.get(key));
|
||||
}
|
||||
|
||||
return admins;
|
||||
|
||||
//OLD
|
||||
|
||||
/*
|
||||
JSONArray whitelist = jsonUtils.loadJson(WHITELIST_FILENAME);
|
||||
ArrayList<MyUser> admins = new ArrayList<>();
|
||||
|
||||
//go through whitelist
|
||||
for (Object o : whitelist) {
|
||||
|
||||
JSONObject userjson = (JSONObject) o;
|
||||
String role = (String) userjson.get("role");
|
||||
|
||||
if (role.equalsIgnoreCase(Roles.ADMIN.name())) {
|
||||
long user_id = (long) userjson.get("id");
|
||||
String user_name = (String) userjson.get("user_name");
|
||||
|
||||
admins.add(new MyUser((int)user_id, null, false, null, user_name, "DE", Roles.ADMIN));
|
||||
}
|
||||
}
|
||||
|
||||
return admins;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load all user out of Whitelist
|
||||
* @return List of Users
|
||||
*/
|
||||
public static ArrayList<MyUser> buildUserList() {
|
||||
log.debug("Build user list");
|
||||
|
||||
ArrayList<MyUser> users = new ArrayList<>();
|
||||
|
||||
for (long key : Core.userMap.keySet()){
|
||||
if (Core.userMap.get(key).getRole() == Roles.USER)
|
||||
users.add(Core.userMap.get(key));
|
||||
}
|
||||
|
||||
return users;
|
||||
|
||||
/*
|
||||
JSONArray whitelist = jsonUtils.loadJson(WHITELIST_FILENAME);
|
||||
|
||||
ArrayList<MyUser> userList = new ArrayList<>();
|
||||
//go through whitelist
|
||||
for (Object o : whitelist) {
|
||||
|
||||
JSONObject userjson = (JSONObject) o;
|
||||
String role = (String) userjson.get("role");
|
||||
if (role.equalsIgnoreCase(Roles.USER.name())) {
|
||||
long user_id = (long) userjson.get("id");
|
||||
String user_name = (String) userjson.get("user_name");
|
||||
JSONArray permissions = (JSONArray) userjson.get("permissions");
|
||||
|
||||
MyUser user = new MyUser((int) user_id, null, false, null, user_name, "DE", Roles.USER);
|
||||
|
||||
List<UserPermission> perms = new ArrayList<>();
|
||||
for (Object x : permissions)
|
||||
perms.add(UserPermission.valueOf((String) x));
|
||||
|
||||
user.setPermission(perms);
|
||||
|
||||
userList.add(user);
|
||||
}
|
||||
}
|
||||
return userList;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* load all Guests ou tof Whitelist
|
||||
* @return List of Guests
|
||||
*/
|
||||
public static ArrayList<MyUser> buildGuestList() {
|
||||
log.debug("Build guest list");
|
||||
|
||||
ArrayList<MyUser> guests = new ArrayList<>();
|
||||
|
||||
for (long key : Core.userMap.keySet()){
|
||||
if (Core.userMap.get(key).getRole() == Roles.GUEST)
|
||||
guests.add(Core.userMap.get(key));
|
||||
}
|
||||
|
||||
return guests;
|
||||
|
||||
/*
|
||||
JSONArray whitelist = jsonUtils.loadJson(WHITELIST_FILENAME);
|
||||
ArrayList<MyUser> guests = new ArrayList<>();
|
||||
|
||||
//go through whitelist
|
||||
for (Object o : whitelist) {
|
||||
|
||||
JSONObject userjson = (JSONObject) o;
|
||||
String role = (String) userjson.get("role");
|
||||
if (role.equalsIgnoreCase(Roles.GUEST.name())) {
|
||||
long user_id = (long) userjson.get("id");
|
||||
String user_name = (String) userjson.get("user_name");
|
||||
|
||||
MyUser user = new MyUser((int) user_id, null, false, null, user_name, "DE", Roles.USER);
|
||||
|
||||
guests.add(user);
|
||||
}
|
||||
}
|
||||
return guests;
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
//Method to load all blocked to a Userlist
|
||||
public static ArrayList<MyUser> buildBlockList() {
|
||||
log.debug("Build block list");
|
||||
JSONArray blocklist = jsonUtils.loadJson(BLOCKLIST_FILENAME);
|
||||
ArrayList<MyUser> blocked = new ArrayList<>();
|
||||
|
||||
//go through whitelist
|
||||
for (Object o : blocklist) {
|
||||
|
||||
JSONObject userjson = (JSONObject) o;
|
||||
|
||||
long user_id = (long) userjson.get("id");
|
||||
String user_name = (String) userjson.get("user_name");
|
||||
|
||||
MyUser user = new MyUser((int) user_id, null, false, null, user_name, "DE", Roles.BLOCKED);
|
||||
|
||||
blocked.add(user);
|
||||
}
|
||||
|
||||
return blocked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user from Whitelist by ID
|
||||
* @param userID id of User
|
||||
* @return MyUser object
|
||||
*/
|
||||
public static MyUser loadUser(long userID){
|
||||
log.debug("load user: " + userID);
|
||||
|
||||
//First lookup user
|
||||
if (Core.userMap.containsKey(userID))
|
||||
return Core.userMap.get(userID);
|
||||
|
||||
JSONArray whitelist = jsonUtils.loadJson(WHITELIST_FILENAME);
|
||||
|
||||
for (Object o : whitelist){
|
||||
|
||||
JSONObject x = (JSONObject) o;
|
||||
|
||||
if ((long)x.get("id") == userID){
|
||||
MyUser user = new MyUser((int)(long)x.get("id"), null, false, null, (String)x.get("user_name"), "DE", Roles.valueOf(((String)x.get("role")).toUpperCase()));
|
||||
|
||||
List<UserPermission> perms = new ArrayList<>();
|
||||
if (x.containsKey("permissions")) {
|
||||
for (Object z : (JSONArray) x.get("permissions")) {
|
||||
//TODO work that shit!
|
||||
perms.add(UserPermission.valueOf((String) z));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
user.setPermission(perms);
|
||||
|
||||
//save to Hashmap
|
||||
//Core.userMap.put(userID, user);
|
||||
|
||||
if (user.getRole() == Roles.ADMIN)
|
||||
Core.userMap.put(userID, user);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user from Blocklist by ID
|
||||
* @param userID id of User
|
||||
* @return MyUser object
|
||||
*/
|
||||
public static MyUser loadBlockedUser(long userID){
|
||||
log.debug("load blocked user: " + userID);
|
||||
|
||||
JSONArray blocklist = jsonUtils.loadJson(BLOCKLIST_FILENAME);
|
||||
|
||||
for (Object o : blocklist){
|
||||
|
||||
JSONObject x = (JSONObject) o;
|
||||
|
||||
if ((long)x.get("id") == userID){
|
||||
return new MyUser((int)(long)x.get("id"), null, false, null, (String)x.get("user_name"), "DE", Roles.BLOCKED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/*------------------------------------------- UTIL ---------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Check Whitelist for Given user if list contains user return true
|
||||
* @param userID userID to check
|
||||
* @return boolean user is in whitelist
|
||||
*/
|
||||
public static boolean checkWhitelist(long userID){
|
||||
|
||||
//First look in Hashmap
|
||||
if (Core.userMap.containsKey(userID))
|
||||
return true;
|
||||
|
||||
JSONArray whitelist = jsonUtils.loadJson(WHITELIST_FILENAME);
|
||||
|
||||
//go through Whitelist
|
||||
for (Object o : whitelist) {
|
||||
|
||||
JSONObject test = (JSONObject) o;
|
||||
long testId = (long) test.get("id");
|
||||
|
||||
//if IDis quall user is in Whitelist
|
||||
if (testId == userID) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Blacklist for Given user if list contains user return true
|
||||
* @param userID userID to check
|
||||
* @return boolean user is in Blacklist
|
||||
*/
|
||||
public static boolean checkBlacklist(long userID){
|
||||
|
||||
JSONArray blacklist = jsonUtils.loadJson(BLOCKLIST_FILENAME);
|
||||
|
||||
//go through Blacklist
|
||||
for (Object o : blacklist) {
|
||||
|
||||
JSONObject test = (JSONObject) o;
|
||||
long testId = (long) test.get("id");
|
||||
|
||||
//if IDis quall user is in Whitelist
|
||||
if (testId == userID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void loadUserList() {
|
||||
log.info("load userList");
|
||||
|
||||
JSONArray whitelist = jsonUtils.loadJson(WHITELIST_FILENAME);
|
||||
|
||||
for (Object o : whitelist) {
|
||||
|
||||
JSONObject x = (JSONObject) o;
|
||||
|
||||
log.debug("JSON: " + x.toString());
|
||||
|
||||
MyUser user = new MyUser((int)(long)x.get("id"),
|
||||
null, false, null,
|
||||
(String)x.get("user_name"), "DE",
|
||||
Roles.valueOf(((String)x.get("role")).toUpperCase()));
|
||||
|
||||
|
||||
List<UserPermission> perms = new ArrayList<>();
|
||||
if (x.containsKey("permissions")) {
|
||||
JSONArray arr = (JSONArray) x.get("permissions");
|
||||
for (Object z : arr) {
|
||||
perms.add(UserPermission.valueOf((String) z));
|
||||
|
||||
}
|
||||
user.setPermission(perms);
|
||||
}
|
||||
|
||||
//save to Hashmap
|
||||
Core.userMap.put((long)user.getId(), user);
|
||||
|
||||
log.debug("HASH: " + user.toStringEXTRA());
|
||||
}
|
||||
}
|
||||
}
|
1250
src/main/java/Modules/AdminMenue.java
Normal file
1250
src/main/java/Modules/AdminMenue.java
Normal file
File diff suppressed because it is too large
Load diff
166
src/main/java/Modules/BasicModule.java
Normal file
166
src/main/java/Modules/BasicModule.java
Normal file
|
@ -0,0 +1,166 @@
|
|||
package Modules;
|
||||
|
||||
|
||||
import CORE.Core;
|
||||
import Manager.UserManager;
|
||||
|
||||
import Utility.KeyBoards;
|
||||
import Utility.MessageConstants;
|
||||
import Utility.User.MyUser;
|
||||
import Utility.User.Roles;
|
||||
|
||||
import Utility.User.State;
|
||||
import org.telegram.telegrambots.meta.api.methods.ParseMode;
|
||||
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
||||
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageText;
|
||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
|
||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static CORE.Core.NO_BOT_RIGHTS;
|
||||
import static java.lang.Math.toIntExact;
|
||||
|
||||
public class BasicModule implements Module {
|
||||
|
||||
private Core core;
|
||||
|
||||
public BasicModule(Core core){
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Update update) {
|
||||
/*----------Update has Text----------*/
|
||||
|
||||
if (update.hasMessage() && update.getMessage().hasText()) {
|
||||
|
||||
String text = update.getMessage().getText();
|
||||
|
||||
long userId = update.getMessage().getFrom().getId();
|
||||
|
||||
State state = core.getUserMap().containsKey(userId) ? core.getUserMap().get(userId).getState() : null;
|
||||
|
||||
//Different Options to build the Main Menu
|
||||
|
||||
/*----------User is known, build main Menu----------*/
|
||||
|
||||
if (text.equalsIgnoreCase("/start") && UserManager.checkWhitelist(update.getMessage().getFrom().getId()) && state == null) {
|
||||
MyUser myUser = UserManager.loadUser(update.getMessage().getFrom().getId());
|
||||
|
||||
SendMessage message = new SendMessage();
|
||||
String message_text;
|
||||
InlineKeyboardMarkup buttons;
|
||||
|
||||
if (myUser.getRole() == Roles.GUEST) {
|
||||
buttons = KeyBoards.buildGuestMenu();
|
||||
message_text = MessageConstants.MESSAGE_MENU_GUEST;
|
||||
} else {
|
||||
buttons = KeyBoards.buildMainMenu(userId);
|
||||
message_text = MessageConstants.MESSAGE_MENU_MAIN;
|
||||
}
|
||||
|
||||
message_text = message_text.replace("$user", CORE.Core.getUserAsMention(update.getMessage().getFrom()));
|
||||
|
||||
message.setChatId(userId).setParseMode(ParseMode.HTML).setReplyMarkup(buttons).setText(message_text);
|
||||
|
||||
core.send_message(message);
|
||||
}
|
||||
|
||||
/*----------User is unknown, build Menu with Open Chat and
|
||||
possibillities to request rights----------*/
|
||||
|
||||
else if (state == null && text.equalsIgnoreCase("/start") && !UserManager.checkBlacklist(update.getMessage().getFrom().getId())) {
|
||||
SendMessage message = new SendMessage();
|
||||
|
||||
InlineKeyboardMarkup buttons = KeyBoards.buildOpenMenu();
|
||||
|
||||
if (NO_BOT_RIGHTS) {
|
||||
message.setChatId(userId).setParseMode(ParseMode.HTML).setReplyMarkup(buttons).setText(
|
||||
MessageConstants.MESSAGE_MENU_OPEN_NO_BOT_RIGHTS);
|
||||
} else {
|
||||
message.setChatId(userId).setParseMode(ParseMode.HTML).setReplyMarkup(buttons).setText(
|
||||
MessageConstants.MESSAGE_MENU_OPEN);
|
||||
}
|
||||
|
||||
core.send_message(message);
|
||||
}
|
||||
|
||||
/*----------/help----------*/
|
||||
|
||||
else if (text.equalsIgnoreCase("/help") && !UserManager.checkBlacklist(update.getMessage().getFrom().getId()) && state == null) {
|
||||
SendMessage message = new SendMessage();
|
||||
|
||||
message.setChatId(userId).setParseMode(ParseMode.HTML).setText(MessageConstants.MESSAGE_HELP);
|
||||
|
||||
core.send_message(message);
|
||||
}
|
||||
|
||||
/*----------/changelog---------*/
|
||||
|
||||
else if (text.equalsIgnoreCase("/changelog") && UserManager.checkWhitelist(update.getMessage().getFrom().getId()) && state == null) {
|
||||
SendMessage message = new SendMessage();
|
||||
|
||||
message.setChatId(userId).setParseMode(ParseMode.HTML).setText(MessageConstants.MESSAGE_CHANGELOG);
|
||||
|
||||
core.send_message(message);
|
||||
}
|
||||
|
||||
/*----------Cancel any state----------*/
|
||||
|
||||
else if (state != null && text.equals("/cancel")) {
|
||||
core.getUserMap().get(userId).setState(null);
|
||||
|
||||
InlineKeyboardMarkup keyboard = new InlineKeyboardMarkup();
|
||||
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
|
||||
row.add(new InlineKeyboardButton().setText("Hauptmenü").setCallbackData("mainmenu"));
|
||||
|
||||
buttons.add(row);
|
||||
|
||||
keyboard.setKeyboard(buttons);
|
||||
|
||||
SendMessage message = new SendMessage().setChatId(userId).setParseMode(ParseMode.HTML).setReplyMarkup(
|
||||
keyboard).setText(MessageConstants.MESSAGE_STATE_CANCELED);
|
||||
|
||||
core.send_message(message);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------Update has Callback Query, aka as Button was clicked----------*/
|
||||
|
||||
else if (update.hasCallbackQuery()) {
|
||||
|
||||
String call_data = update.getCallbackQuery().getData();
|
||||
|
||||
long message_id = update.getCallbackQuery().getMessage().getMessageId();
|
||||
long user_id = update.getCallbackQuery().getFrom().getId();
|
||||
|
||||
//Go back to Main Menu
|
||||
if (call_data.equals("mainmenu") && UserManager.checkWhitelist(update.getCallbackQuery().getFrom().getId())) {
|
||||
EditMessageText message = new EditMessageText();
|
||||
|
||||
InlineKeyboardMarkup keyboard = KeyBoards.buildMainMenu(user_id);
|
||||
|
||||
String message_text = MessageConstants.MESSAGE_MENU_MAIN.replace("$user", CORE.Core.getUserAsMention(update.getCallbackQuery().getFrom()));
|
||||
|
||||
message.setChatId(user_id).setParseMode(ParseMode.HTML).setMessageId(toIntExact(message_id))
|
||||
.setReplyMarkup(keyboard).setText(message_text);
|
||||
|
||||
core.edit_message(message);
|
||||
}
|
||||
|
||||
//Close Menu
|
||||
else if (call_data.equals("close")) {
|
||||
EditMessageText message = new EditMessageText().setChatId(user_id).setMessageId(toIntExact(message_id))
|
||||
.setText(MessageConstants.MESSAGE_MENU_CLOSED);
|
||||
|
||||
core.edit_message(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
314
src/main/java/Modules/ModCommands.java
Normal file
314
src/main/java/Modules/ModCommands.java
Normal file
|
@ -0,0 +1,314 @@
|
|||
package Modules;
|
||||
|
||||
import CORE.Core;
|
||||
import Manager.UserManager;
|
||||
import Utility.KeyBoards;
|
||||
import Utility.MessageConstants;
|
||||
import Utility.User.MyUser;
|
||||
import Utility.User.Roles;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.telegram.telegrambots.meta.api.methods.ParseMode;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMember;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.RestrictChatMember;
|
||||
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
||||
import org.telegram.telegrambots.meta.api.objects.*;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ModCommands implements Module {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private Core core;
|
||||
|
||||
public ModCommands(Core core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
public void execute(Update update) {
|
||||
|
||||
//Filter for text not from bots
|
||||
if (update.hasMessage() && update.getMessage().hasText() && !update.getMessage().getFrom().getBot()) {
|
||||
|
||||
//Filter for only Admins
|
||||
//TODO May implement for moderator
|
||||
//TODO implement Unban
|
||||
if (UserManager.checkAdmin(update.getMessage().getFrom().getId())) {
|
||||
|
||||
///////////////////////
|
||||
// BAN
|
||||
///////////////////////
|
||||
if (update.getMessage().getText().matches("(?is:/ban.*)")) {
|
||||
|
||||
//Wenn auf etwas geantwortet banne User der nachricht
|
||||
MyUser user;
|
||||
|
||||
//Ban via answer author
|
||||
if (update.getMessage().isReply()) {
|
||||
|
||||
user = getUserFromReply(update.getMessage().getReplyToMessage());
|
||||
|
||||
//Sonst versuche einen User heraus zu lesen.
|
||||
} else if (update.getMessage().hasEntities() || getUserFromEntetie(update.getMessage()) != null) {
|
||||
|
||||
org.telegram.telegrambots.meta.api.objects.User tgUser = getUserFromEntetie(update.getMessage());
|
||||
user = new MyUser(tgUser.getId(), Core.getUserAsMention(tgUser), Roles.BLOCKED);
|
||||
|
||||
//sonst fehler
|
||||
} else {
|
||||
SendMessage message = new SendMessage()
|
||||
.setChatId(update.getMessage().getChat().getId())
|
||||
.setReplyToMessageId(update.getMessage().getMessageId())
|
||||
.setText(MessageConstants.ERROR);
|
||||
core.send_message(message);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug("Command Ban by " + update.getMessage().getFrom().getId() + " - " + Core.getUserAsMention(update.getMessage().getFrom()));
|
||||
|
||||
SendMessage message = new SendMessage()
|
||||
.setChatId((long) update.getMessage().getFrom().getId())
|
||||
.setText(MessageConstants.MESSAGE_ADMINTOOLS_ABOUTTOBLOCK.replace("$user", user.getUserName()))
|
||||
.setReplyMarkup(KeyBoards.buildBlockOptions(user))
|
||||
.setParseMode(ParseMode.HTML);
|
||||
|
||||
core.send_message(message);
|
||||
|
||||
///////////////////////
|
||||
// Mute
|
||||
///////////////////////
|
||||
} else if (update.getMessage().getText().matches("(?is:/mute.*)")) {
|
||||
|
||||
//Wenn auf etwas geantwortet banne User der nachricht
|
||||
MyUser user;
|
||||
|
||||
//Mute via answer author
|
||||
if (update.getMessage().isReply()) {
|
||||
|
||||
user = getUserFromReply(update.getMessage().getReplyToMessage());
|
||||
|
||||
//Sonst versuche einen User heraus zu lesen.
|
||||
} else if (update.getMessage().hasEntities() || getUserFromEntetie(update.getMessage()) != null) {
|
||||
|
||||
org.telegram.telegrambots.meta.api.objects.User tgUser = getUserFromEntetie(update.getMessage());
|
||||
user = new MyUser(tgUser.getId(), Core.getUserAsMention(tgUser));
|
||||
} else {
|
||||
SendMessage message = new SendMessage()
|
||||
.setChatId(update.getMessage().getChat().getId())
|
||||
.setReplyToMessageId(update.getMessage().getMessageId())
|
||||
.setText(MessageConstants.ERROR);
|
||||
core.send_message(message);
|
||||
return;
|
||||
}
|
||||
|
||||
muteUser(user.getId());
|
||||
|
||||
SendMessage message = new SendMessage()
|
||||
.setChatId(update.getMessage().getChat().getId())
|
||||
.setReplyToMessageId(update.getMessage().getMessageId())
|
||||
.setText("OK");
|
||||
core.send_message(message);
|
||||
|
||||
//notify Admins about mute
|
||||
message = new SendMessage()
|
||||
.setText(
|
||||
MessageConstants.MESSAGE_PERMISSION_MUTED_ADMIN_FROM
|
||||
.replace("$user", user.getUserName())
|
||||
.replace("$admin", Core.getUserAsMention(update.getMessage().getFrom()))
|
||||
)
|
||||
.setParseMode(ParseMode.HTML);
|
||||
core.send_message_toadmins(message);
|
||||
|
||||
|
||||
///////////////////////
|
||||
// UnMute
|
||||
///////////////////////
|
||||
} else if (update.getMessage().getText().matches("(?is:/unmute.*)")) {
|
||||
|
||||
//Wenn auf etwas geantwortet banne User der nachricht
|
||||
MyUser user;
|
||||
|
||||
//UnMute via answer author
|
||||
if (update.getMessage().isReply()) {
|
||||
|
||||
user = getUserFromReply(update.getMessage().getReplyToMessage());
|
||||
|
||||
//Sonst versuche einen User heraus zu lesen.
|
||||
} else if (update.getMessage().hasEntities() || getUserFromEntetie(update.getMessage()) != null) {
|
||||
|
||||
org.telegram.telegrambots.meta.api.objects.User tgUser = getUserFromEntetie(update.getMessage());
|
||||
user = new MyUser(tgUser.getId(), Core.getUserAsMention(tgUser));
|
||||
|
||||
} else {
|
||||
SendMessage message = new SendMessage()
|
||||
.setChatId(update.getMessage().getChat().getId())
|
||||
.setReplyToMessageId(update.getMessage().getMessageId())
|
||||
.setText(MessageConstants.ERROR);
|
||||
core.send_message(message);
|
||||
return;
|
||||
}
|
||||
|
||||
unMuteUser(user.getId());
|
||||
|
||||
SendMessage message = new SendMessage()
|
||||
.setChatId(update.getMessage().getChat().getId())
|
||||
.setReplyToMessageId(update.getMessage().getMessageId())
|
||||
.setText("OK");
|
||||
core.send_message(message);
|
||||
|
||||
//notify Admins about mute
|
||||
message = new SendMessage()
|
||||
.setText(
|
||||
MessageConstants.MESSAGE_PERMISSION_UNMUTED_ADMIN_FROM
|
||||
.replace("$user", user.getUserName())
|
||||
.replace("$admin", Core.getUserAsMention(update.getMessage().getFrom()))
|
||||
)
|
||||
.setParseMode(ParseMode.HTML);
|
||||
core.send_message_toadmins(message);
|
||||
|
||||
///////////////////////
|
||||
// Grant
|
||||
///////////////////////
|
||||
} else if (update.getMessage().getText().matches("(?is:/promote.*)") || update.getMessage().getText().matches("(?is:/prom.*)")) {
|
||||
|
||||
//Wenn auf etwas geantwortet banne User der nachricht
|
||||
MyUser user;
|
||||
|
||||
//Promote via answer author
|
||||
if (update.getMessage().isReply()) {
|
||||
|
||||
user = getUserFromReply(update.getMessage().getReplyToMessage());
|
||||
|
||||
//Sonst versuche einen User heraus zu lesen.
|
||||
} else if (update.getMessage().hasEntities() || getUserFromEntetie(update.getMessage()) != null) {
|
||||
|
||||
org.telegram.telegrambots.meta.api.objects.User tgUser = getUserFromEntetie(update.getMessage());
|
||||
user = new MyUser(tgUser.getId(), Core.getUserAsMention(tgUser), Roles.GUEST);
|
||||
|
||||
} else {
|
||||
SendMessage message = new SendMessage()
|
||||
.setChatId(update.getMessage().getChat().getId())
|
||||
.setReplyToMessageId(update.getMessage().getMessageId())
|
||||
.setText(MessageConstants.ERROR);
|
||||
core.send_message(message);
|
||||
return;
|
||||
}
|
||||
|
||||
core.getOpen_requests().put((long)user.getId(), new MyUser(user.getId(), user.getUserName(), Roles.GUEST));
|
||||
|
||||
SendMessage message = new SendMessage()
|
||||
.setChatId((long) update.getMessage().getFrom().getId())
|
||||
.setText(MessageConstants.MESSAGE_PERMISSION_OPENUSER_GUEST.replace("$user", user.getUserName()))
|
||||
.setReplyMarkup(KeyBoards.buildRequestAnswers(user.getId()))
|
||||
.setParseMode(ParseMode.HTML);
|
||||
core.send_message(message);
|
||||
|
||||
//////////////////////////////
|
||||
// Add Chat to WatchingChats
|
||||
/////////////////////////////
|
||||
} else if (update.getMessage().getText().matches("(?is:/init)")) {
|
||||
|
||||
core.getWatchingChats().add(update.getMessage().getChat().getId());
|
||||
core.saveWhatchingChats();
|
||||
|
||||
//////////////////////////////
|
||||
// Add Chat to WatchingChats
|
||||
/////////////////////////////
|
||||
} else if (update.getMessage().getText().matches("(?is:/exit)")) {
|
||||
|
||||
core.getWatchingChats().remove(update.getMessage().getChat().getId());
|
||||
core.saveWhatchingChats();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void muteUser(int userID) {
|
||||
|
||||
for (long chat : core.getWatchingChats()) {
|
||||
RestrictChatMember action = new RestrictChatMember()
|
||||
.forTimePeriod(Duration.ofMinutes(Core.MUTETIMER))
|
||||
.setCanSendMessages(false)
|
||||
.setChatId(chat)
|
||||
.setUserId(userID)
|
||||
.setCanAddWebPagePreviews(false)
|
||||
.setCanSendMediaMessages(false)
|
||||
.setCanSendOtherMessages(false);
|
||||
try {
|
||||
action.validate();
|
||||
core.execute(action);
|
||||
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
unMuteUser(action.getUserId());
|
||||
}
|
||||
}, TimeUnit.MINUTES.toMillis(Core.MUTETIMER));
|
||||
|
||||
} catch (TelegramApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void unMuteUser(int userID) {
|
||||
for (long chat : core.getWatchingChats()) {
|
||||
RestrictChatMember revoce = new RestrictChatMember()
|
||||
.setCanSendMessages(true)
|
||||
.setChatId(chat)
|
||||
.setUserId(userID)
|
||||
.setCanAddWebPagePreviews(true)
|
||||
.setCanSendMediaMessages(true)
|
||||
.setCanSendOtherMessages(true);
|
||||
try {
|
||||
revoce.validate();
|
||||
core.execute(revoce);
|
||||
} catch (TelegramApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private MyUser getUserFromEntetie(Message message) {
|
||||
|
||||
for (MessageEntity x : message.getEntities()) {
|
||||
|
||||
//if its no no username mention all good id is given
|
||||
if (x.getType().matches("(?i:text_mention)") && x.getUser() != null) {
|
||||
return new MyUser(x.getUser().getId(), Core.getUserAsMention(x.getUser()));
|
||||
|
||||
//else ID is missing ... so look nake up
|
||||
} else if (x.getType().matches("(?i:mention)") && x.getUser() != null) {
|
||||
|
||||
GetChatMember getChatMember = new GetChatMember()
|
||||
.setChatId(x.getUser().getUserName());
|
||||
try {
|
||||
getChatMember.validate();
|
||||
User user = core.execute(getChatMember).getUser();
|
||||
return new MyUser(user.getId(), Core.getUserAsMention(user));
|
||||
} catch (TelegramApiException e){
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private MyUser getUserFromReply(Message message){
|
||||
//if replay is to join message use the new chat member mentioned
|
||||
if (message.getNewChatMembers() != null && message.getNewChatMembers().size() > 0)
|
||||
return new MyUser(message.getNewChatMembers().get(0).getId(), Core.getUserAsMention(message.getNewChatMembers().get(0)));
|
||||
else
|
||||
return new MyUser(message.getFrom().getId(), Core.getUserAsMention(message.getFrom()), Roles.BLOCKED); }
|
||||
}
|
||||
|
8
src/main/java/Modules/Module.java
Normal file
8
src/main/java/Modules/Module.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package Modules;
|
||||
|
||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||
|
||||
public interface Module {
|
||||
|
||||
void execute(Update update);
|
||||
}
|
104
src/main/java/Modules/SlowMode.java
Normal file
104
src/main/java/Modules/SlowMode.java
Normal file
|
@ -0,0 +1,104 @@
|
|||
package Modules;
|
||||
|
||||
import CORE.Core;
|
||||
import Manager.UserManager;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.RestrictChatMember;
|
||||
import org.telegram.telegrambots.meta.api.methods.updatingmessages.DeleteMessage;
|
||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static CORE.Core.SLOWMODETIMER;
|
||||
|
||||
public class SlowMode implements Module{
|
||||
|
||||
private Core core;
|
||||
private static final Logger logger = LoggerFactory.getLogger(SlowMode.class);
|
||||
|
||||
public SlowMode(Core core){
|
||||
|
||||
this.core = core;
|
||||
|
||||
}
|
||||
|
||||
public void execute(Update update) {
|
||||
|
||||
logger.debug("Got a Message:\n\t" + update.toString());
|
||||
|
||||
//Filter for Messages only from Group-Chats and watch chats
|
||||
if (update.hasMessage()
|
||||
&& (update.getMessage().getChat().isSuperGroupChat() || update.getMessage().getChat().isGroupChat())
|
||||
&& core.getWatchingChats().contains(update.getMessage().getChatId())
|
||||
&& update.getMessage().getNewChatMembers().size() == 0) {
|
||||
|
||||
//Check if user as a role
|
||||
if (UserManager.loadUser(update.getMessage().getFrom().getId()) == null || UserManager.loadUser(update.getMessage().getFrom().getId()).getRole() == null) {
|
||||
|
||||
//using restrictions for slowmode
|
||||
slowModeActive(update.getMessage().getFrom().getId(), update.getMessage().getChat().getId());
|
||||
|
||||
if (!update.getMessage().hasText()) {
|
||||
|
||||
logger.info("DELETE MESSAGE:\n\t" + update.toString());
|
||||
|
||||
DeleteMessage del = new DeleteMessage()
|
||||
.setMessageId(update.getMessage().getMessageId())
|
||||
.setChatId(update.getMessage().getChatId());
|
||||
|
||||
try {
|
||||
del.validate();
|
||||
core.execute(del);
|
||||
} catch (TelegramApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void slowModeActive(int userID, long chatID){
|
||||
RestrictChatMember action = new RestrictChatMember()
|
||||
.forTimePeriod(Duration.ofSeconds(SLOWMODETIMER))
|
||||
.setCanSendMessages(false)
|
||||
.setChatId(chatID)
|
||||
.setUserId(userID)
|
||||
.setCanAddWebPagePreviews(false)
|
||||
.setCanSendMediaMessages(false)
|
||||
.setCanSendOtherMessages(false);
|
||||
|
||||
try {
|
||||
action.validate();
|
||||
core.execute(action);
|
||||
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
RestrictChatMember revoce = new RestrictChatMember()
|
||||
.setCanSendMessages(true)
|
||||
.setChatId(action.getChatId())
|
||||
.setUserId(action.getUserId())
|
||||
.setCanAddWebPagePreviews(true)
|
||||
.setCanSendMediaMessages(true)
|
||||
.setCanSendOtherMessages(true);
|
||||
try {
|
||||
revoce.validate();
|
||||
core.execute(revoce);
|
||||
} catch (TelegramApiException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, TimeUnit.SECONDS.toMillis(SLOWMODETIMER));
|
||||
|
||||
} catch (TelegramApiException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
173
src/main/java/Modules/UserMenue.java
Normal file
173
src/main/java/Modules/UserMenue.java
Normal file
|
@ -0,0 +1,173 @@
|
|||
package Modules;
|
||||
|
||||
import CORE.Core;
|
||||
import Manager.ChatManager;
|
||||
import Manager.UserManager;
|
||||
import Utility.KeyBoards;
|
||||
import Utility.MessageConstants;
|
||||
import Utility.User.MyUser;
|
||||
import Utility.User.Roles;
|
||||
import Utility.chat.ChatCategory;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.telegram.telegrambots.meta.api.methods.ParseMode;
|
||||
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
||||
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageText;
|
||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
|
||||
|
||||
import static java.lang.Math.toIntExact;
|
||||
|
||||
public class UserMenue implements Module {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(UserManager.class);
|
||||
|
||||
private Core core;
|
||||
|
||||
public UserMenue(Core core){
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(Update update) {
|
||||
|
||||
if (update.hasCallbackQuery()) {
|
||||
String call_data = update.getCallbackQuery().getData();
|
||||
|
||||
long message_id = update.getCallbackQuery().getMessage().getMessageId();
|
||||
long user_id = update.getCallbackQuery().getFrom().getId();
|
||||
String user_name = Core.getUserAsMention(update.getCallbackQuery().getFrom());
|
||||
|
||||
/*----------Permission handling----------*/
|
||||
|
||||
///////////////////////////////////////////
|
||||
// PERMISSION HANDLING
|
||||
///////////////////////////////////////////
|
||||
|
||||
if (call_data.startsWith("permission") && !UserManager.checkBlacklist(user_id)) {
|
||||
String[] call_data_parts = call_data.split(" ");
|
||||
|
||||
// User is allready on whitelist
|
||||
if (UserManager.checkWhitelist(user_id)) {
|
||||
EditMessageText message = new EditMessageText();
|
||||
|
||||
message.setChatId(user_id).setParseMode(ParseMode.HTML).setMessageId(toIntExact(message_id))
|
||||
.setText(MessageConstants.MESSAGE_PERMISSION_ALLREADYONWHITELIST);
|
||||
|
||||
core.edit_message(message);
|
||||
}
|
||||
|
||||
// User allready requested Permission
|
||||
else if (core.getOpen_requests().containsKey(user_id)) {
|
||||
EditMessageText message = new EditMessageText();
|
||||
|
||||
message.setChatId(user_id).setParseMode(ParseMode.HTML).setMessageId(toIntExact(message_id))
|
||||
.setText(MessageConstants.MESSAGE_PERMISSION_ALLREADYREQUESTED);
|
||||
|
||||
core.edit_message(message);
|
||||
}
|
||||
|
||||
// New User requested permission
|
||||
else if (call_data_parts[1].equals("request")) {
|
||||
|
||||
// Add user request to List of open requests
|
||||
core.getOpen_requests().put(user_id, new MyUser((int) user_id, user_name, Roles.USER));
|
||||
|
||||
// Edit user message to tell him, that his request got received
|
||||
EditMessageText message = new EditMessageText();
|
||||
|
||||
message.setChatId(user_id).setParseMode(ParseMode.HTML).setMessageId(toIntExact(message_id))
|
||||
.setText(MessageConstants.MESSAGE_PERMISSION_USER_REQUEST_RECEIVED);
|
||||
|
||||
core.edit_message(message);
|
||||
|
||||
// Send message to Admingroup, that there is a new request
|
||||
SendMessage admin_message = new SendMessage();
|
||||
|
||||
String admin_message_text = MessageConstants.MESSAGE_PERMISSION_USER_REQUEST.replace("$user",
|
||||
user_name);
|
||||
|
||||
admin_message.setParseMode(ParseMode.HTML).setText(admin_message_text);
|
||||
|
||||
core.send_message_toadmins(admin_message);
|
||||
}
|
||||
|
||||
// New Guest requested permission
|
||||
else if (call_data_parts[1].equals("requestguest")) {
|
||||
|
||||
// Add user request to List of open requests
|
||||
MyUser guest = new MyUser((int) user_id, user_name, Roles.GUEST);
|
||||
core.getOpen_requests().put(user_id, guest);
|
||||
|
||||
// Edit user message to tell him, that his request got received
|
||||
EditMessageText message = new EditMessageText();
|
||||
|
||||
message.setChatId(user_id).setParseMode(ParseMode.HTML).setMessageId(toIntExact(message_id))
|
||||
.setText(MessageConstants.MESSAGE_PERMISSION_USER_REQUEST_RECEIVED);
|
||||
|
||||
core.edit_message(message);
|
||||
|
||||
// Send message to Admingroup, that there is a new request
|
||||
SendMessage admin_message = new SendMessage();
|
||||
|
||||
String admin_message_text = MessageConstants.MESSAGE_PERMISSION_GUEST_REQUEST.replace("$user",
|
||||
user_name);
|
||||
|
||||
admin_message.setParseMode(ParseMode.HTML).setText(admin_message_text);
|
||||
|
||||
core.send_message_toadmins(admin_message);
|
||||
}
|
||||
}
|
||||
/////////////////////////////
|
||||
// Chat Browsing
|
||||
////////////////////////////
|
||||
else if (call_data.startsWith("chats") && !UserManager.checkBlacklist(user_id)) {
|
||||
String[] call_data_parts = call_data.split(" ");
|
||||
|
||||
/*----------Load all Categories----------*/
|
||||
|
||||
if (call_data_parts[1].equalsIgnoreCase("menu")) {
|
||||
InlineKeyboardMarkup keyboardMarkup = KeyBoards.buildCategoriesMenu(user_id);
|
||||
|
||||
EditMessageText messageText = new EditMessageText().setChatId(user_id).setMessageId(
|
||||
toIntExact(message_id)).setParseMode(ParseMode.HTML).setReplyMarkup(keyboardMarkup).setText(
|
||||
MessageConstants.MESSAGE_CHATS_MENU);
|
||||
|
||||
core.edit_message(messageText);
|
||||
}
|
||||
|
||||
/*----------Load specific category----------*/
|
||||
|
||||
else if (call_data_parts[1].equalsIgnoreCase("loadcategory")) {
|
||||
long uid = Long.parseLong(call_data_parts[2]);
|
||||
ChatCategory category = ChatManager.loadCategory(uid);
|
||||
|
||||
InlineKeyboardMarkup keyboardMarkup = KeyBoards.buildCategory(category, user_id);
|
||||
|
||||
String messageText = category.getName() + ":";
|
||||
|
||||
EditMessageText message = new EditMessageText().setChatId(user_id).setMessageId(
|
||||
toIntExact(message_id)).setParseMode(ParseMode.HTML).setReplyMarkup(keyboardMarkup).setText(
|
||||
messageText);
|
||||
|
||||
core.edit_message(message);
|
||||
} else if (call_data_parts[1].equalsIgnoreCase("permissionmissing")) {
|
||||
long uid = Long.parseLong(call_data_parts[2]);
|
||||
ChatCategory category = ChatManager.loadCategory(uid);
|
||||
|
||||
InlineKeyboardMarkup keyboardMarkup = KeyBoards.buildBackToCategory(category);
|
||||
|
||||
EditMessageText message = new EditMessageText()
|
||||
.setChatId(user_id)
|
||||
.setMessageId(Math.toIntExact(message_id))
|
||||
.setParseMode(ParseMode.HTML).setReplyMarkup(keyboardMarkup)
|
||||
.setText(MessageConstants.MESSAGE_CHATS_NORIGHTS);
|
||||
|
||||
core.edit_message(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
45
src/main/java/Modules/Welcome.java
Normal file
45
src/main/java/Modules/Welcome.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package Modules;
|
||||
|
||||
import CORE.Core;
|
||||
import Utility.MessageConstants;
|
||||
import org.telegram.telegrambots.meta.api.methods.ParseMode;
|
||||
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
||||
|
||||
import static CORE.Core.SLOWMODETIMER;
|
||||
|
||||
public class Welcome implements Module {
|
||||
|
||||
private Core core;
|
||||
|
||||
public Welcome(Core core){
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Update update) {
|
||||
|
||||
//TODO Welcome Hardcoded, may do it dynamical
|
||||
//When new member joined Utility.chat, welcome him and dont go on further
|
||||
if (update.hasMessage() && (update.getMessage().getChat().isGroupChat() || update.getMessage().getChat().isSuperGroupChat())
|
||||
&& update.getMessage().getNewChatMembers().size() > 0
|
||||
&& update.getMessage().getChatId() == (long) (-1001287901992L)) {
|
||||
for (User i : update.getMessage().getNewChatMembers()) {
|
||||
SendMessage message = new SendMessage()
|
||||
.setParseMode(ParseMode.HTML)
|
||||
.setChatId(update.getMessage().getChat().getId())
|
||||
.setText(MessageConstants.WELCOME_MESSAGE
|
||||
.replaceAll("\\$user", Core.getUserAsMention(i))
|
||||
.replaceAll("\\$time", SLOWMODETIMER + "")
|
||||
);
|
||||
try {
|
||||
core.execute(message);
|
||||
} catch (TelegramApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
621
src/main/java/Utility/KeyBoards.java
Normal file
621
src/main/java/Utility/KeyBoards.java
Normal file
|
@ -0,0 +1,621 @@
|
|||
package Utility;
|
||||
|
||||
import Manager.ChatManager;
|
||||
import Manager.UserManager;
|
||||
|
||||
import Utility.User.MyUser;
|
||||
import Utility.User.Roles;
|
||||
import Utility.User.UserPermission;
|
||||
import Utility.chat.Chat;
|
||||
import Utility.chat.ChatCategory;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
|
||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static CORE.Core.*;
|
||||
|
||||
public class KeyBoards {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(KeyBoards.class);
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// CORE MENUE
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
public static InlineKeyboardMarkup buildGuestMenu() {
|
||||
log.debug("Building guest menu");
|
||||
|
||||
InlineKeyboardMarkup keyboard = new InlineKeyboardMarkup();
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
//List<InlineKeyboardButton> row2 = new ArrayList<>();
|
||||
//row2.add(new InlineKeyboardButton().setText("Gästechat / Guest chat").setUrl(GUEST_CHAT_JOIN_LINK));
|
||||
//buttons.add(row2);
|
||||
|
||||
for (Object chat : OPEN_CHATS) {
|
||||
JSONObject chatJSON = (JSONObject) chat;
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
row.add(new InlineKeyboardButton().setText((String) chatJSON.get("name"))
|
||||
.setUrl((String) chatJSON.get("url")));
|
||||
buttons.add(row);
|
||||
}
|
||||
|
||||
List<InlineKeyboardButton> row3 = new ArrayList<>();
|
||||
row3.add(new InlineKeyboardButton().setText("Menü schließen / Close menu").setCallbackData("close"));
|
||||
buttons.add(row3);
|
||||
|
||||
keyboard.setKeyboard(buttons);
|
||||
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildMainMenu(long user_id) {
|
||||
log.debug("Building main menu");
|
||||
|
||||
InlineKeyboardMarkup main_menu = new InlineKeyboardMarkup();
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
for (Object chat : OPEN_CHATS) {
|
||||
JSONObject chatJSON = (JSONObject) chat;
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
row.add(new InlineKeyboardButton().setText((String) chatJSON.get("name"))
|
||||
.setUrl((String) chatJSON.get("url")));
|
||||
buttons.add(row);
|
||||
}
|
||||
|
||||
List<InlineKeyboardButton> row1 = new ArrayList<>();
|
||||
row1.add(new InlineKeyboardButton().setText("Chats").setCallbackData("chats menu"));
|
||||
|
||||
buttons.add(row1);
|
||||
|
||||
if (UserManager.checkAdmin(user_id)) {
|
||||
List<InlineKeyboardButton> adminbutton = new ArrayList<>();
|
||||
adminbutton.add(new InlineKeyboardButton().setText("AdminTools").setCallbackData("admintools menu"));
|
||||
buttons.add(adminbutton);
|
||||
}
|
||||
|
||||
List<InlineKeyboardButton> close = new ArrayList<>();
|
||||
close.add(new InlineKeyboardButton().setText("Menü schließen").setCallbackData("close"));
|
||||
|
||||
buttons.add(close);
|
||||
|
||||
main_menu.setKeyboard(buttons);
|
||||
|
||||
return main_menu;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildOpenMenu() {
|
||||
log.info("Building open menu");
|
||||
|
||||
InlineKeyboardMarkup open_menu = new InlineKeyboardMarkup();
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
for (Object chat : OPEN_CHATS) {
|
||||
JSONObject chatJSON = (JSONObject) chat;
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
row.add(new InlineKeyboardButton().setText((String) chatJSON.get("name"))
|
||||
.setUrl((String) chatJSON.get("url")));
|
||||
buttons.add(row);
|
||||
}
|
||||
|
||||
if (!NO_BOT_RIGHTS) {
|
||||
List<InlineKeyboardButton> row2 = new ArrayList<>();
|
||||
row2.add(new InlineKeyboardButton().setText("Rechte anfragen").setCallbackData("permission request"));
|
||||
buttons.add(row2);
|
||||
}
|
||||
|
||||
List<InlineKeyboardButton> row3 = new ArrayList<>();
|
||||
row3.add(new InlineKeyboardButton().setText("Gastrechte anfragen")
|
||||
.setCallbackData("permission requestguest"));
|
||||
buttons.add(row3);
|
||||
|
||||
open_menu.setKeyboard(buttons);
|
||||
|
||||
return open_menu;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// ADMIN MENUE
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
public static InlineKeyboardMarkup buildAdminMenu() {
|
||||
|
||||
InlineKeyboardMarkup keyboard = new InlineKeyboardMarkup();
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row2 = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row3 = new ArrayList<>();
|
||||
|
||||
row.add(new InlineKeyboardButton().setText("Offene Requests").setCallbackData("admintools loadrequests"));
|
||||
row2.add(new InlineKeyboardButton().setText("Whitelist").setCallbackData("admintools whitelist"));
|
||||
row2.add(new InlineKeyboardButton().setText("Blocklist").setCallbackData("admintools blocklist"));
|
||||
row3.add(new InlineKeyboardButton().setText("Zurück").setCallbackData("mainmenu"));
|
||||
|
||||
buttons.add(row);
|
||||
buttons.add(row2);
|
||||
buttons.add(row3);
|
||||
|
||||
keyboard.setKeyboard(buttons);
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildOpenRequests(Map<Long, MyUser> open_requests) {
|
||||
|
||||
InlineKeyboardMarkup requests = new InlineKeyboardMarkup();
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < open_requests.size(); i++) {
|
||||
buttons.add(new ArrayList<>());
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (long user_id : open_requests.keySet()) {
|
||||
MyUser user = open_requests.get(user_id);
|
||||
String user_name = user.getUserName();
|
||||
String buttontext;
|
||||
if (user.getRole() == Roles.GUEST) {
|
||||
buttontext = "Gastanfrage: " + user_name.replaceAll("(?is:<[^>]+>)", "");
|
||||
} else {
|
||||
buttontext = user_name.replaceAll("(?is:<[^>]+>)", "");
|
||||
}
|
||||
InlineKeyboardButton user_button = new InlineKeyboardButton().setText(buttontext).setCallbackData(
|
||||
"admintools loadopenuser " + user_id);
|
||||
buttons.get(i).add(user_button);
|
||||
i++;
|
||||
}
|
||||
|
||||
List<InlineKeyboardButton> lastbutton = new ArrayList<>();
|
||||
lastbutton.add(new InlineKeyboardButton().setText("Zurück.").setCallbackData("admintools menu"));
|
||||
buttons.add(lastbutton);
|
||||
|
||||
requests.setKeyboard(buttons);
|
||||
|
||||
return requests;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildRequestAnswers(long user_id) {
|
||||
|
||||
InlineKeyboardMarkup keyboard = new InlineKeyboardMarkup();
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row2 = new ArrayList<>();
|
||||
|
||||
row.add(new InlineKeyboardButton().setText("Ja")
|
||||
.setCallbackData("admintools grant " + user_id));
|
||||
row.add(new InlineKeyboardButton().setText("Nein")
|
||||
.setCallbackData("admintools deny " + user_id));
|
||||
row.add(new InlineKeyboardButton().setText("Block")
|
||||
.setCallbackData("admintools denyandblock " + user_id));
|
||||
row2.add(new InlineKeyboardButton().setText("Zurück").setCallbackData("admintools loadrequests"));
|
||||
|
||||
buttons.add(row);
|
||||
buttons.add(row2);
|
||||
|
||||
keyboard.setKeyboard(buttons);
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildWhitelistMenu() {
|
||||
|
||||
InlineKeyboardMarkup keyboard = new InlineKeyboardMarkup();
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row2 = new ArrayList<>();
|
||||
|
||||
row.add(new InlineKeyboardButton().setText("Spezifischen Nutzer laden").setCallbackData("admintools loaduser"));
|
||||
row2.add(new InlineKeyboardButton().setText("Zurück").setCallbackData("admintools menu"));
|
||||
|
||||
buttons.add(row);
|
||||
buttons.add(row2);
|
||||
|
||||
keyboard.setKeyboard(buttons);
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildBlocklistMenu() {
|
||||
|
||||
InlineKeyboardMarkup keyboard = new InlineKeyboardMarkup();
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row2 = new ArrayList<>();
|
||||
|
||||
row.add(new InlineKeyboardButton().setText("Unblock").setCallbackData("admintools unblock"));
|
||||
row2.add(new InlineKeyboardButton().setText("Zurück").setCallbackData("admintools menu"));
|
||||
|
||||
buttons.add(row);
|
||||
buttons.add(row2);
|
||||
|
||||
keyboard.setKeyboard(buttons);
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildAdminFound(MyUser user) {
|
||||
InlineKeyboardMarkup keyboard = new InlineKeyboardMarkup();
|
||||
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row2 = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row3 = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row4 = new ArrayList<>();
|
||||
|
||||
row.add(new InlineKeyboardButton().setText("Degradieren")
|
||||
.setCallbackData("admintools changeadmin " + user.getId()));
|
||||
row2.add(new InlineKeyboardButton().setText("Zu Gast ändern")
|
||||
.setCallbackData("admintools changeguest " + user.getId()));
|
||||
row3.add(new InlineKeyboardButton().setText("Blockieren")
|
||||
.setCallbackData("admintools block " + user.getId()));
|
||||
row4.add(new InlineKeyboardButton().setText("Zurück").setCallbackData("admintools whitelist"));
|
||||
|
||||
buttons.add(row);
|
||||
buttons.add(row2);
|
||||
buttons.add(row3);
|
||||
buttons.add(row4);
|
||||
|
||||
keyboard.setKeyboard(buttons);
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildGuestFound(MyUser user) {
|
||||
InlineKeyboardMarkup keyboard = new InlineKeyboardMarkup();
|
||||
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row2 = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row3 = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row4 = new ArrayList<>();
|
||||
|
||||
row.add(new InlineKeyboardButton().setText("Zum Admin berufen")
|
||||
.setCallbackData("admintools changeadmin " + user.getId()));
|
||||
row2.add(new InlineKeyboardButton().setText("Zu normalem Nutzer machen")
|
||||
.setCallbackData("admintools changeguest " + user.getId()));
|
||||
row3.add(new InlineKeyboardButton().setText("Blockieren")
|
||||
.setCallbackData("admintools block " + user.getId()));
|
||||
row4.add(new InlineKeyboardButton().setText("Zurück").setCallbackData("admintools whitelist"));
|
||||
|
||||
buttons.add(row);
|
||||
buttons.add(row2);
|
||||
buttons.add(row3);
|
||||
buttons.add(row4);
|
||||
|
||||
keyboard.setKeyboard(buttons);
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildUserFound(MyUser user) {
|
||||
InlineKeyboardMarkup keyboard = new InlineKeyboardMarkup();
|
||||
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row2 = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row3 = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row4 = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row5 = new ArrayList<>();
|
||||
|
||||
row.add(new InlineKeyboardButton().setText("Zum Admin berufen")
|
||||
.setCallbackData("admintools changeadmin " + user.getId()));
|
||||
row2.add(new InlineKeyboardButton().setText("Zu Gast ändern")
|
||||
.setCallbackData("admintools changeguest " + user.getId()));
|
||||
row2.add(new InlineKeyboardButton().setText("Mod ändern")
|
||||
.setCallbackData("admintools changemod " + user.getId()));
|
||||
row3.add(new InlineKeyboardButton().setText("Operator ändern")
|
||||
.setCallbackData("admintools changeoperator " + user.getId()));
|
||||
row3.add(new InlineKeyboardButton().setText("Hightrust ändern")
|
||||
.setCallbackData("admintools changehightrust " + user.getId()));
|
||||
row4.add(new InlineKeyboardButton().setText("Blockieren")
|
||||
.setCallbackData("admintools block " + user.getId()));
|
||||
row5.add(new InlineKeyboardButton().setText("Zurück").setCallbackData("admintools whitelist"));
|
||||
|
||||
buttons.add(row);
|
||||
buttons.add(row2);
|
||||
buttons.add(row3);
|
||||
buttons.add(row4);
|
||||
buttons.add(row5);
|
||||
|
||||
keyboard.setKeyboard(buttons);
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildBlockOptions(MyUser user) {
|
||||
InlineKeyboardMarkup keyboard = new InlineKeyboardMarkup();
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
|
||||
row.add(new InlineKeyboardButton().setText("BLOCK").setCallbackData("admintools blockapproval " + user.getId()));
|
||||
row.add(new InlineKeyboardButton().setText("Zurück").setCallbackData("admintools whitelist"));
|
||||
|
||||
buttons.add(row);
|
||||
|
||||
keyboard.setKeyboard(buttons);
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildBackButtonAdmintools() {
|
||||
|
||||
InlineKeyboardMarkup keyboard = new InlineKeyboardMarkup();
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
|
||||
row.add(new InlineKeyboardButton().setText("Zurück").setCallbackData("admintools menu"));
|
||||
|
||||
buttons.add(row);
|
||||
|
||||
keyboard.setKeyboard(buttons);
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildBackButtonWhitelist() {
|
||||
|
||||
InlineKeyboardMarkup keyboard = new InlineKeyboardMarkup();
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
|
||||
row.add(new InlineKeyboardButton().setText("Zurück").setCallbackData("admintools whitelist"));
|
||||
|
||||
buttons.add(row);
|
||||
|
||||
keyboard.setKeyboard(buttons);
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
// CHATS MENUE
|
||||
/////////////////////////////////////////
|
||||
|
||||
public static InlineKeyboardMarkup buildCategoriesMenu(long user_id) {
|
||||
log.debug("Building categories menu for user " + user_id);
|
||||
List<ChatCategory> categories = ChatManager.loadCategories();
|
||||
|
||||
InlineKeyboardMarkup keyboardMarkup = new InlineKeyboardMarkup();
|
||||
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < categories.size(); i++) {
|
||||
buttons.add(new ArrayList<>());
|
||||
}
|
||||
|
||||
MyUser user = UserManager.loadUser(user_id);
|
||||
|
||||
for (int i = 0; i < categories.size(); i++) {
|
||||
|
||||
//check for at least one valid chat in category
|
||||
boolean hasPermission = false;
|
||||
for (Chat x : categories.get(i).getChatList()) {
|
||||
if (user != null && (user.getRole() == Roles.ADMIN || ( x.getPermissionNeeded() != null && x.getPermissionNeeded() == UserPermission.NORMAL ) || ( x.getPermissionNeeded() != null && user.getPermission().contains(x.getPermissionNeeded())))) {
|
||||
hasPermission = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//only add chat if it contains at leas one valid chat
|
||||
if (hasPermission)
|
||||
buttons.get(i).add(new InlineKeyboardButton().setText(categories.get(i).getName())
|
||||
.setCallbackData("chats loadcategory " + categories.get(i).getUid()));
|
||||
|
||||
}
|
||||
|
||||
if (UserManager.checkAdmin(user_id)) {
|
||||
List<InlineKeyboardButton> adminButtons = new ArrayList<>();
|
||||
|
||||
adminButtons.add(
|
||||
new InlineKeyboardButton().setText("Kategorie hinzufügen").setCallbackData("chats addcategory"));
|
||||
|
||||
buttons.add(adminButtons);
|
||||
}
|
||||
|
||||
List<InlineKeyboardButton> backButton = new ArrayList<>();
|
||||
backButton.add(new InlineKeyboardButton().setText("Zurück").setCallbackData("mainmenu"));
|
||||
buttons.add(backButton);
|
||||
|
||||
keyboardMarkup.setKeyboard(buttons);
|
||||
|
||||
return keyboardMarkup;
|
||||
}
|
||||
|
||||
|
||||
public static InlineKeyboardMarkup buildCategory(ChatCategory category, long userId) {
|
||||
log.debug("Building category " + category.getName() + " for user " + userId);
|
||||
|
||||
InlineKeyboardMarkup keyboardMarkup = new InlineKeyboardMarkup();
|
||||
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < (category.getChatList().size() + 1) / 2; i++) {
|
||||
buttons.add(new ArrayList<>());
|
||||
}
|
||||
|
||||
MyUser abstractUser = UserManager.loadUser(userId);
|
||||
|
||||
for (int i = 0; i < category.getChatList().size(); i++) {
|
||||
|
||||
Chat chat = category.getChatList().get(i);
|
||||
InlineKeyboardButton button = new InlineKeyboardButton();
|
||||
|
||||
if (abstractUser != null && abstractUser.getRole() == Roles.ADMIN) {
|
||||
if (chat.getUrl() == null) {
|
||||
button.setText(chat.getName()).setCallbackData("chats notfound");
|
||||
} else {
|
||||
button.setText(chat.getFullName()).setUrl(chat.getUrl());
|
||||
}
|
||||
} else {
|
||||
//show if permission match
|
||||
if (abstractUser != null && chat.getPermissionNeeded() != null && abstractUser.getPermission().contains(chat.getPermissionNeeded())) {
|
||||
if (chat.getUrl() == null) {
|
||||
button.setText(chat.getFullName()).setCallbackData("chats notfound");
|
||||
} else {
|
||||
button.setText(chat.getFullName()).setUrl(chat.getUrl());
|
||||
}
|
||||
//Show if no permission is given
|
||||
} else if (chat.getPermissionNeeded() == null) {
|
||||
if (chat.getUrl() == null) {
|
||||
button.setText(chat.getFullName()).setCallbackData("chats notfound");
|
||||
} else {
|
||||
button.setText(chat.getFullName()).setUrl(chat.getUrl());
|
||||
}
|
||||
//else wrong permission set
|
||||
} else {
|
||||
button.setText(chat.getFullName()).setCallbackData("chats permissionmissing");
|
||||
}
|
||||
}
|
||||
|
||||
buttons.get(i / 2).add(button);
|
||||
}
|
||||
|
||||
|
||||
if (UserManager.checkAdmin(userId)) {
|
||||
List<InlineKeyboardButton> adminButton = new ArrayList<>();
|
||||
adminButton.add(new InlineKeyboardButton().setText("Kategorie bearbeiten")
|
||||
.setCallbackData("chats editcategory " + category.getUid()));
|
||||
buttons.add(adminButton);
|
||||
}
|
||||
|
||||
List<InlineKeyboardButton> backButton = new ArrayList<>();
|
||||
backButton.add(new InlineKeyboardButton().setText("Zurück").setCallbackData("chats menu"));
|
||||
buttons.add(backButton);
|
||||
|
||||
keyboardMarkup.setKeyboard(buttons);
|
||||
return keyboardMarkup;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildEditCategory(ChatCategory category) {
|
||||
log.debug("Building edit category for " + category.getName());
|
||||
InlineKeyboardMarkup keyboardMarkup = new InlineKeyboardMarkup();
|
||||
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row2 = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row3 = new ArrayList<>();
|
||||
|
||||
row.add(new InlineKeyboardButton().setText("Chat hinzufügen").setCallbackData("chats addchat " + category.getUid()));
|
||||
row.add(new InlineKeyboardButton().setText("Chat bearbeiten").setCallbackData("chats editchat " + category.getUid()));
|
||||
row2.add(new InlineKeyboardButton().setText("Kategorie löschen").setCallbackData("chats deletecategory " + category.getUid()));
|
||||
row3.add(new InlineKeyboardButton().setText("Zurück").setCallbackData("chats loadcategory " + category.getUid()));
|
||||
|
||||
buttons.add(row);
|
||||
buttons.add(row2);
|
||||
buttons.add(row3);
|
||||
|
||||
keyboardMarkup.setKeyboard(buttons);
|
||||
|
||||
return keyboardMarkup;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildPossiblePermissions() {
|
||||
InlineKeyboardMarkup keyboardMarkup = new InlineKeyboardMarkup();
|
||||
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row2 = new ArrayList<>();
|
||||
|
||||
row.add(new InlineKeyboardButton().setText("Keine spezielle Berechtigung").setCallbackData("chats addpermission NORMAL"));
|
||||
row.add(new InlineKeyboardButton().setText("Hightrust").setCallbackData("chats addpermission HIGHTRUST"));
|
||||
row2.add(new InlineKeyboardButton().setText("Mod").setCallbackData("chats addpermission MOD"));
|
||||
row2.add(new InlineKeyboardButton().setText("Operator").setCallbackData("chats addpermission OPERATOR"));
|
||||
|
||||
buttons.add(row);
|
||||
buttons.add(row2);
|
||||
|
||||
keyboardMarkup.setKeyboard(buttons);
|
||||
|
||||
return keyboardMarkup;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildBackToCategory(ChatCategory category) {
|
||||
InlineKeyboardMarkup keyboardMarkup = new InlineKeyboardMarkup();
|
||||
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
|
||||
row.add(new InlineKeyboardButton().setText("Zurück").setCallbackData("chats loadcategory " + category.getUid()));
|
||||
|
||||
buttons.add(row);
|
||||
|
||||
keyboardMarkup.setKeyboard(buttons);
|
||||
|
||||
return keyboardMarkup;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildChangePermissions() {
|
||||
InlineKeyboardMarkup keyboardMarkup = new InlineKeyboardMarkup();
|
||||
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row2 = new ArrayList<>();
|
||||
|
||||
row.add(new InlineKeyboardButton().setText("Keine spezielle Berechtigung").setCallbackData("chats changepermissionconfirm NORMAL"));
|
||||
row.add(new InlineKeyboardButton().setText("Hightrust").setCallbackData("chats changepermissionconfirm HIGHTRUST"));
|
||||
row2.add(new InlineKeyboardButton().setText("Mod").setCallbackData("chats changepermissionconfirm MOD"));
|
||||
row2.add(new InlineKeyboardButton().setText("Operator").setCallbackData("chats changepermissionconfirm OPERATOR"));
|
||||
|
||||
buttons.add(row);
|
||||
buttons.add(row2);
|
||||
|
||||
keyboardMarkup.setKeyboard(buttons);
|
||||
|
||||
return keyboardMarkup;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildEditChat(Chat chat, long categoryUid) {
|
||||
InlineKeyboardMarkup keyboardMarkup = new InlineKeyboardMarkup();
|
||||
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row2 = new ArrayList<>();
|
||||
List<InlineKeyboardButton> row3 = new ArrayList<>();
|
||||
|
||||
row.add(new InlineKeyboardButton().setText("UID ändern").setCallbackData("chats changeuid " + chat.getUid() + " " + categoryUid));
|
||||
row.add(new InlineKeyboardButton().setText("Name ändern").setCallbackData("chats changename " + chat.getUid() + " " + categoryUid));
|
||||
row2.add(new InlineKeyboardButton().setText("Permission ändern").setCallbackData("chats changepermission " + chat.getUid() + " " + categoryUid));
|
||||
row2.add(new InlineKeyboardButton().setText("Url ändern").setCallbackData("chats changeurl " + chat.getUid() + " " + categoryUid));
|
||||
row3.add(new InlineKeyboardButton().setText("Löschen").setCallbackData("chats deletechat " + chat.getUid() + " " + categoryUid));
|
||||
row3.add(new InlineKeyboardButton().setText("Zurück").setCallbackData("chats editcategory " + categoryUid + " " + categoryUid));
|
||||
|
||||
buttons.add(row);
|
||||
buttons.add(row2);
|
||||
buttons.add(row3);
|
||||
|
||||
keyboardMarkup.setKeyboard(buttons);
|
||||
|
||||
return keyboardMarkup;
|
||||
}
|
||||
|
||||
public static InlineKeyboardMarkup buildConfirmCategoryDelete(ChatCategory category) {
|
||||
InlineKeyboardMarkup keyboardMarkup = new InlineKeyboardMarkup();
|
||||
|
||||
List<List<InlineKeyboardButton>> buttons = new ArrayList<>();
|
||||
|
||||
List<InlineKeyboardButton> row = new ArrayList<>();
|
||||
|
||||
row.add(new InlineKeyboardButton().setText("LÖSCHEN").setCallbackData("chats deletecategoryconfirm " + category.getUid()));
|
||||
row.add(new InlineKeyboardButton().setText("Zurück").setCallbackData("chats editcategory " + category.getUid()));
|
||||
|
||||
buttons.add(row);
|
||||
|
||||
keyboardMarkup.setKeyboard(buttons);
|
||||
|
||||
return keyboardMarkup;
|
||||
}
|
||||
|
||||
}
|
111
src/main/java/Utility/MessageConstants.java
Normal file
111
src/main/java/Utility/MessageConstants.java
Normal file
|
@ -0,0 +1,111 @@
|
|||
package Utility;
|
||||
|
||||
import CORE.Core;
|
||||
|
||||
public class MessageConstants {
|
||||
public static final String MESSAGE_MENU_MAIN = "Willkommen $user! \nAktuell findest du hier nur unsere Telegram Chats, in Zukunft sollen hier aber durchaus noch weitere Funktionen dazukommen.";
|
||||
public static final String MESSAGE_MENU_GUEST = "Willkommen $user! \nHier findest du unsere offenen Chats:";
|
||||
public static final String MESSAGE_MENU_OPEN = "Willkommen bei " + Core.TEAM_NAME + "! \nEs scheint, als hättest du keine Berechtigungen um diesen Bot zu nutzen. Wenn du neu bei " + Core.TEAM_NAME + " bist, dann frage doch einfach Rechte an. Falls du Gast bist, hast du hier die Möglichkeit Gastrechte anzufragen.\n\nIf you are a guest, just request guest permissions to join our guest Utility.chat.";
|
||||
public static final String MESSAGE_MENU_OPEN_NO_BOT_RIGHTS = "Willkommen bei " + Core.TEAM_NAME + "! \nHier "
|
||||
+ "findest "
|
||||
+ "du unsere offenen Chats.\nWenn du aktives Communitymitglied bist frage bitte Rechte an. Sonst frage bitte Gastrechte an!";
|
||||
public static final String MESSAGE_MENU_CLOSED = "Menü erfolgreich geschlossen. Neustart mit /start .";
|
||||
|
||||
//public static final String MESSAGE_ERROR_NOUSERNAME = "Hi! Dieser Bot funktioniert leider nur mit einem festgelegten Telegram-Nutzernamen. Bitte stelle dir in deinen Telegram Einstellungen einen Nutzernamen ein und starte den Bot dann mit /start neu. Danke!";
|
||||
|
||||
public static final String MESSAGE_PERMISSION_USER_REQUEST = "Der Nutzer $user hat Berechtigungen für den Bot angefragt.";
|
||||
public static final String MESSAGE_PERMISSION_GUEST_REQUEST = "Der Nutzer $user hat Gastrechte für den Bot angefragt.";
|
||||
public static final String MESSAGE_PERMISSION_USER_REQUEST_GRANTED = "$user wurden von $admin Botrechte verliehen.";
|
||||
public static final String MESSAGE_PERMISSION_GUEST_REQUEST_GRANTED = "$user wurden von $admin Gastrechte verliehen.";
|
||||
public static final String MESSAGE_PERMISSION_USER_REQUEST_RECEIVED = "Deine Anfrage wurde an ein Team hochtrainierter Affen weitergeleitet.\nYou request has been forwarded to a team of highly trained monkeys.";
|
||||
public static final String MESSAGE_PERMISSION_ALLREADYONWHITELIST = "Es tut mir Leid, aber du stehst bereits auf der Whitelist.";
|
||||
public static final String MESSAGE_PERMISSION_ALLREADYREQUESTED = "Geduld mein junger Padawan! Deine Anfrage wurde bereits weitergeleitet und muss noch von einem Admin bearbeitet werden.\n\nPlease be patient, your request has already been forwarded and is awaiting approval.";
|
||||
public static final String MESSAGE_PERMISSION_OPENREQUESTS = "Es gibt offene Requests von:";
|
||||
public static final String MESSAGE_PERMISSION_NO_OPENREQUESTS = "Es gibt aktuell keine offenen Requests.";
|
||||
public static final String MESSAGE_PERMISSION_OPENUSER = "$user hat volle Rechte angefragt. Akzeptieren?";
|
||||
public static final String MESSAGE_PERMISSION_OPENUSER_GUEST = "$user hat Gastrechte angefragt. Akzeptieren?";
|
||||
public static final String MESSAGE_PERMISSION_GRANTED = "Du hast soeben Berechtigungen für diesen Bot bekommen. Um den Bot zu nutzen starte ihn bitte mit /start neu.";
|
||||
public static final String MESSAGE_PERMISSION_GRANTED_ADMIN = "$user wurde auf die Whitelist gesetzt.";
|
||||
public static final String MESSAGE_PERMISSION_GUEST_GRANTED = "Du hast soeben Gastrechte (für " + (Core.GUEST_TIME/1200/1000) + "h) für diesen Bot bekommen. Um den Bot zu nutzen starte ihn bitte mit /start neu.\nYou were given guest permission for the bot (for " + (Core.GUEST_TIME/1200/1000) + "h). Please restart the bot using /start to proceed.";
|
||||
public static final String MESSAGE_PERMISSION_GUEST_GRANTED_ADMIN = "$user wurde zur Gästeliste hinzugefügt.";
|
||||
public static final String MESSAGE_PERMISSION_DENIED = "Deine Nutzungsanfrage wurde abgelehnt.";
|
||||
public static final String MESSAGE_PERMISSION_DENIED_ADMIN = "Nutzungsanfrage von $user wurde abgelehnt.";
|
||||
public static final String MESSAGE_PERMISSION_REQUEST_DENIED = "Nutzungsanfrage von $user wurde von $admin abgelehnt.";
|
||||
public static final String MESSAGE_PERMISSION_BLOCKED = "Du wurdest blockiert.";
|
||||
public static final String MESSAGE_PERMISSION_BLOCKED_ADMIN = "$user wurde geblockt.";
|
||||
public static final String MESSAGE_PERMISSION_BLOCKED_ADMIN_FROM = "$user wurde geblockt von $admin.";
|
||||
|
||||
public static final String MESSAGE_ADMINTOOLS_WHITELIST = "Aktuelle Nutzer auf der Whitelist: \n\n";
|
||||
public static final String MESSAGE_ADMINTOOLS_BLOCKLIST = "Aktuell auf der Blocklist: \n\n";
|
||||
public static final String MESSAGE_ADMINTOOLS_LOADUSER = "Okay! Bitte schick mir den exakten Benutzer ID des Users, den du laden möchtest, oder brich mit /cancel ab.";
|
||||
public static final String MESSAGE_ADMINTOOLS_USERNOTFOUND = "Es tut mir Leid, aber ich kann diesen Nutzer nicht finden.";
|
||||
public static final String MESSAGE_ADMINTOOLS_NULLREQUEST = "Es tut mir Leid, aber scheinbar wurde diese Request bereits bearbeitet.";
|
||||
public static final String MESSAGE_ADMINTOOLS_USERFOUND = "Nutzer gefunden: $user\n\n Der Nutzer hat folgende Permissions:\n";
|
||||
public static final String MESSAGE_ADMINTOOLS_ADMINFOUND = "Admin gefunden: $user";
|
||||
public static final String MESSAGE_ADMINTOOLS_GUESTFOUND = "Gast gefunden: $user";
|
||||
public static final String MESSAGE_ADMINTOOLS_CANTCHANGEMASTER = "HOW DARE YOU! Es ist leider nicht möglich den Großmeister zu laden, oder seine Rechte zu ändern.";
|
||||
public static final String MESSAGE_ADMINTOOLS_ABOUTTOBLOCK = "Bist du dir ganz sicher, dass du $user blockieren möchtest?";
|
||||
public static final String MESSAGE_ADMINTOOLS_CANTCHANGESELF = "Es tut mir Leid, aber du kannst deinen eigenen Usereintrag nicht bearbeiten.";
|
||||
public static final String MESSAGE_ADMINTOOLS_BLOCKED = "$user wurde erfolgreich blockiert.";
|
||||
public static final String MESSAGE_ADMINTOOLS_UNBLOCK = "Okay! Bitte schick mir den exakten Benutzernamen des Users, den du freigeben möchtest, oder brich mit /cancel ab.";
|
||||
public static final String MESSAGE_ADMINTOOLS_USERUNBLOCKED = "Okay! $user wurde entblockt und kann eine neue Berechtigungsanfrage für den Bot stellen.";
|
||||
public static final String MESSAGE_ADMINTOOLS_SPAM_DETECTED = "Darf ich $user Blocken? Ich musste einige seiner Nachrichten Löschen!";
|
||||
|
||||
public static final String MESSAGE_CHATS_MENU = "Chatkategorien:";
|
||||
public static final String MESSAGE_CHATS_ADDCATEGORY = "Okay! Bitte gib mir einen Namen für die neue Kategorie.";
|
||||
public static final String MESSAGE_CHATS_CATEGORYADDED = "Okay, Kategorie hinzugefügt. \n\nChatkategorien:";
|
||||
public static final String MESSAGE_CHATS_NORIGHTS = "Es tut mir Leid, aber für diesen Chat brauchst du spezielle Berechtigungen. Wende dich bitte an einen der Mods, wenn du diesem Chat beitreten möchtest.";
|
||||
public static final String MESSAGE_CHATS_NOTFOUND = "Es tut mir Leid, aber ich kann diesen Chat nicht finden.";
|
||||
public static final String MESSAGE_CHATS_ADMINEDITCATEGORY = "Okay, du möchtest die Kategorie $category bearbeiten.";
|
||||
public static final String MESSAGE_CHATS_ADDCHATUID = "Okay! Bitte gib mit zuerst eine noch nicht verwendete Chatnummer (maximal 4 stelliger Integerwert) für den hat.";
|
||||
public static final String MESSAGE_CHATS_ADDCHATNAME = "Danke! Nun gib mir bitte den Namen des Chats.";
|
||||
public static final String MESSAGE_CHATS_NOTANUMBER = "Es tut mir Leid, aber das ist keine valide Nummer. Bitte versuche es noch einmal.";
|
||||
public static final String MESSAGE_CHATS_NOTAURL = "Es tut mir Leid, aber das ist keine valide URL. Bitte versuche es noch einmal.";
|
||||
public static final String MESSAGE_CHATS_CHATEXISTSALLREADY = "Es tut mir Leid, aber dieser Chat existiert bereits. Bitte versuche es noch einmal.";
|
||||
public static final String MESSAGE_CHATS_ADDURL = "Nun sende mir bitte die Chat URL.";
|
||||
public static final String MESSAGE_CHATS_CHATNUMBERTOLONG = "Es tut mir Leid, aber diese Nummer ist zu lang. Bitte versuche es noch einmal.";
|
||||
public static final String MESSAGE_CHATS_ADDPERMISSION = "Alles klar! Braucht der Chat spezielle Rechte?";
|
||||
public static final String MESSAGE_CHATS_CHATADDED = "Chat erfolgreich hinzugefügt.";
|
||||
public static final String MESSAGE_CHATS_ADMINDELETECATEGORY = "Bist du dir ganz sicher, dass du die Kategorie <b>$category</b> löschen möchtest? Das kann nicht rückgängig gemacht werden!";
|
||||
public static final String MESSAGE_CHATS_ADMINCATEGORYDELETED = "Kategorie erfolgreich gelöscht.";
|
||||
public static final String MESSAGE_CHATS_LOADCHAT = "Bitte sende mir die exakte ID des Chats, den du bearbeiten möchtest.";
|
||||
public static final String MESSAGE_CHATS_CHATFOUND = "<b>Chat gefunden: $fullname</b> \n\nBenötigte Permission: $permission\nURL: $url";
|
||||
public static final String MESSAGE_CHATS_CHATDELETED = "Chat erfolgreich gelöscht.";
|
||||
public static final String MESSAGE_CHATS_CHANGEUID = "Okay, sende mir die neue UID.";
|
||||
public static final String MESSAGE_CHATS_CHANGENAME = "Okay, sende mir den neuen Namen.";
|
||||
public static final String MESSAGE_CHATS_CHANGEPERMISSION = "Welche Permission benötigt der Chat?";
|
||||
public static final String MESSAGE_CHATS_CHANGEURL = "Okay, sende mir die neue URL.";
|
||||
|
||||
|
||||
public static final String MESSAGE_HELP = "Hallo! Ich bin ein Bot der " + Core.TEAM_NAME + "! Wenn du mich "
|
||||
+ "nutzen willst, dann "
|
||||
+ "starte mich bitte mit /start.";
|
||||
|
||||
public static final String MESSAGE_CHANGELOG = "<b>Changelog " + Core.TEAM_NAME + "_bot</b>\n" +
|
||||
"\n" +
|
||||
"<i>Ver 1.0.0</i>\n" +
|
||||
"Initial Version\n" +
|
||||
"\n" +
|
||||
"<i>Ver 1.0.1</i>\n" +
|
||||
"Added temporary Anomaly Chats";
|
||||
|
||||
public static final String MESSAGE_STATE_CANCELED = "Erfolgreich abgebrochen.";
|
||||
|
||||
public static final String MESSAGE_BLOCKED = "Du bist für diesen Bot geblockt.";
|
||||
|
||||
public static final String WELCOME_MESSAGE = "Hallo $user!\n" +
|
||||
"\n" +
|
||||
"Herzlich willkommen bei Mittweida for Future!\n" +
|
||||
"Stelle dich bitte kurz der Gruppe vor, damit wir mehr über dich erfahren können. Zurzeit kannst du nur aller $time Sekunden eine Nachricht schreiben. Bitte schreibe mich an und klicke auf \"Rechte anfragen\" um unsere Chats vollständig nutzen zu können.\n" +
|
||||
"Vielen Dank!\n\n" +
|
||||
"Mit dem betreten dieses Chats stimmst du unseren Regeln / Chatiquette zu! (in der Beschreibung verlinkt)\n\n" +
|
||||
"Unseren Info-Channel für gebündelte Informationen findest du unter @MittweidaForFutureInfo";
|
||||
|
||||
public static final String GUEST_EXPIRED = "Deine Gastrechte sind abgelaufen. Du kannst sie erneut anfragen oder nach permanenten Rechten fragen.\n" +
|
||||
"Your guest permissions are expired. You can request them again or ask for permanent Permission.";
|
||||
|
||||
public static final String MESSAGE_NO_PERMISSION = "Es tut mir leid, aber du hast keine ausreichenden Berechtigungen!";
|
||||
public static final String MESSAGE_PERMISSION_MUTED_ADMIN_FROM = "$user wurde gemutet von $admin.";
|
||||
public static final String MESSAGE_PERMISSION_UNMUTED_ADMIN_FROM = "$user wurde unmutet von $admin.";
|
||||
public static final String ERROR = "Sum Sum";
|
||||
}
|
31
src/main/java/Utility/User/GuestHandle.java
Normal file
31
src/main/java/Utility/User/GuestHandle.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package Utility.User;
|
||||
|
||||
import CORE.Core;
|
||||
import Manager.UserManager;
|
||||
import Utility.MessageConstants;
|
||||
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
||||
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class GuestHandle extends TimerTask implements Runnable{
|
||||
|
||||
private long userID;
|
||||
private Core core;
|
||||
|
||||
public GuestHandle(Core core, long userID){
|
||||
this.core = core;
|
||||
this.userID = userID;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
UserManager.removeUser(userID);
|
||||
|
||||
SendMessage message = new SendMessage()
|
||||
.setChatId(userID)
|
||||
.setText(MessageConstants.GUEST_EXPIRED);
|
||||
|
||||
core.send_message(message);
|
||||
}
|
||||
}
|
100
src/main/java/Utility/User/MyUser.java
Normal file
100
src/main/java/Utility/User/MyUser.java
Normal file
|
@ -0,0 +1,100 @@
|
|||
package Utility.User;
|
||||
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MyUser extends User {
|
||||
private Roles role = null;
|
||||
private List<UserPermission> permission = null;
|
||||
private State state = null;
|
||||
|
||||
public MyUser(User user, Roles role, List<UserPermission> permissions){
|
||||
super(user.getId(), user.getFirstName(), user.getBot(), user.getLastName(), user.getUserName(), user.getLanguageCode());
|
||||
this.role = role;
|
||||
this.permission = permissions;
|
||||
}
|
||||
|
||||
public MyUser(User user, Roles role){
|
||||
super(user.getId(), user.getFirstName(), user.getBot(), user.getLastName(), user.getUserName(), user.getLanguageCode());
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public MyUser(Integer id, String firstName, Boolean isBot, String lastName, String userName, String languageCode, Roles role, List<UserPermission> permissions) {
|
||||
super(id, firstName, isBot, lastName, userName, languageCode);
|
||||
this.role = role;
|
||||
this.permission = permissions;
|
||||
}
|
||||
|
||||
public MyUser(Integer id, String firstName, Boolean isBot, String lastName, String userName, String languageCode, Roles role) {
|
||||
super(id, firstName, isBot, lastName, userName, languageCode);
|
||||
this.role = role;
|
||||
permission = null;
|
||||
}
|
||||
|
||||
public MyUser(Integer id, String firstName, Boolean isBot, String lastName, String userName, String languageCode) {
|
||||
super(id, firstName, isBot, lastName, userName, languageCode);
|
||||
role = null;
|
||||
permission = null;
|
||||
}
|
||||
|
||||
public MyUser(Integer id, String userName){
|
||||
super(id, null, false, null, userName, "DE");
|
||||
role = null;
|
||||
permission = null;
|
||||
}
|
||||
|
||||
public MyUser(Integer id, String userName, Roles role){
|
||||
super(id, null, false, null, userName, "DE");
|
||||
this.role = role;
|
||||
permission = null;
|
||||
}
|
||||
|
||||
public MyUser(Integer id, String userName, Roles role, List<UserPermission> permission){
|
||||
super(id, null, false, null, userName, "DE");
|
||||
this.role = role;
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public MyUser(){
|
||||
super();
|
||||
role = null;
|
||||
permission = null;
|
||||
}
|
||||
|
||||
public Roles getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(Roles role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public List<UserPermission> getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
public void setPermission(List<UserPermission> permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public void changePermission(UserPermission permission){
|
||||
if (!this.permission.contains(permission)){
|
||||
this.permission.add(permission);
|
||||
} else {
|
||||
this.permission.remove(permission);
|
||||
}
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(State state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String toStringEXTRA(){
|
||||
return (this).toString() + "ROLE: " + (role == null ? "null" : role.name() ) + " PERMISSIONS: " + (permission == null ? "null" : permission.toString()) + " || ";
|
||||
}
|
||||
}
|
5
src/main/java/Utility/User/Roles.java
Normal file
5
src/main/java/Utility/User/Roles.java
Normal file
|
@ -0,0 +1,5 @@
|
|||
package Utility.User;
|
||||
|
||||
public enum Roles {
|
||||
BLOCKED, GUEST, USER, ADMIN
|
||||
}
|
5
src/main/java/Utility/User/State.java
Normal file
5
src/main/java/Utility/User/State.java
Normal file
|
@ -0,0 +1,5 @@
|
|||
package Utility.User;
|
||||
|
||||
public enum State {
|
||||
ADMIN_LOADUSER, ADMIN_UNBLOCKUSER, ADMIN_ADDCHATCATEGORY, ADMIN_ADDCHATUID, ADMIN_ADDCHATNAME, ADMIN_ADDCHATURL, ADMIN_EDITCHAT, ADMIN_CHANGECHATUID, ADMIN_CHANGECHATNAME, ADMIN_CHANGECHATURL
|
||||
}
|
5
src/main/java/Utility/User/UserPermission.java
Normal file
5
src/main/java/Utility/User/UserPermission.java
Normal file
|
@ -0,0 +1,5 @@
|
|||
package Utility.User;
|
||||
|
||||
public enum UserPermission {
|
||||
NORMAL, HIGHTRUST, MOD, OPERATOR, SILENCED
|
||||
}
|
58
src/main/java/Utility/chat/Chat.java
Normal file
58
src/main/java/Utility/chat/Chat.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
package Utility.chat;
|
||||
|
||||
import Utility.User.UserPermission;
|
||||
|
||||
public class Chat {
|
||||
private long uid;
|
||||
private String name;
|
||||
private String url;
|
||||
private UserPermission permissionNeeded;
|
||||
|
||||
public Chat(long uid, String name) {
|
||||
this.uid = uid;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Chat(long uid, String name, String url, UserPermission permissionNeeded) {
|
||||
this.uid = uid;
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
this.permissionNeeded = permissionNeeded;
|
||||
}
|
||||
|
||||
public void setUid(long uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public long getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public void setPermissionNeeded(UserPermission permissionNeeded) {
|
||||
this.permissionNeeded = permissionNeeded;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getFullName() {
|
||||
return "[" + String.valueOf(uid) + "] " + name;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public UserPermission getPermissionNeeded() {
|
||||
return permissionNeeded;
|
||||
}
|
||||
}
|
48
src/main/java/Utility/chat/ChatCategory.java
Normal file
48
src/main/java/Utility/chat/ChatCategory.java
Normal file
|
@ -0,0 +1,48 @@
|
|||
package Utility.chat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChatCategory {
|
||||
private long uid;
|
||||
private String name;
|
||||
private List<Chat> chatList;
|
||||
|
||||
public ChatCategory(long uid, String name) {
|
||||
this.uid = uid;
|
||||
this.name = name;
|
||||
chatList = new ArrayList<>();
|
||||
}
|
||||
|
||||
public long getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void setUid(int uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Chat> getChatList() {
|
||||
return chatList;
|
||||
}
|
||||
|
||||
public void setChatList(List<Chat> chatList) {
|
||||
this.chatList = chatList;
|
||||
}
|
||||
|
||||
public void addChat(Chat chat) {
|
||||
chatList.add(chat);
|
||||
}
|
||||
|
||||
public void removeChat(Chat chat) {
|
||||
chatList.remove(chat);
|
||||
}
|
||||
}
|
40
src/main/java/Utility/jsonUtils.java
Normal file
40
src/main/java/Utility/jsonUtils.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
package Utility;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class jsonUtils {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(jsonUtils.class);
|
||||
public static final String path = new File(System.getProperty("java.class.path")).getAbsoluteFile().getParentFile().getAbsolutePath() + File.separator;
|
||||
|
||||
public static JSONArray loadJson(String filename) {
|
||||
log.debug("Loading " + filename + " from disk");
|
||||
try {
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONArray whitelist = (JSONArray) parser.parse(new FileReader(path + filename));
|
||||
return whitelist;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JSONArray whitelist = new JSONArray();
|
||||
return whitelist;
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveJson(JSONArray json, String filename) {
|
||||
log.debug("Saving " + filename + " to disk");
|
||||
try (FileWriter file = new FileWriter(path + filename)) {
|
||||
file.write(json.toJSONString());
|
||||
file.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
1
src/main/resources/blocklist.json
Normal file
1
src/main/resources/blocklist.json
Normal file
|
@ -0,0 +1 @@
|
|||
[]
|
14
src/main/resources/chats.json
Normal file
14
src/main/resources/chats.json
Normal file
|
@ -0,0 +1,14 @@
|
|||
[
|
||||
{
|
||||
"uid":1,
|
||||
"name":"Allgemein",
|
||||
"chats": [
|
||||
{
|
||||
"uid":1,
|
||||
"permissionNeeded":"NORMAL",
|
||||
"name":"TESTNAME",
|
||||
"url":"http:\/\/google.de"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
20
src/main/resources/config.json
Normal file
20
src/main/resources/config.json
Normal file
|
@ -0,0 +1,20 @@
|
|||
[
|
||||
{
|
||||
"teamname": "Mittweida For Future",
|
||||
"masterUserId": 187200447,
|
||||
"openChats": [
|
||||
{
|
||||
"name": "Diskussionsforum",
|
||||
"url": "https://t.me/fridaysForFutureMittweida"
|
||||
},
|
||||
{
|
||||
"name": "Informationschannel",
|
||||
"url": "https://t.me/MittweidaForFutureInfo"
|
||||
}
|
||||
],
|
||||
"guestChatJoinLink": "",
|
||||
"no_bot_rights_option": false,
|
||||
"botUserName": "MittweidaForFuture_bot",
|
||||
"botToken": "988601954:AAEBCJjz5O0guvVt5ZK0pGYrMLG24yDRBDE"
|
||||
}
|
||||
]
|
44
src/main/resources/log4j.properties
Normal file
44
src/main/resources/log4j.properties
Normal file
|
@ -0,0 +1,44 @@
|
|||
# Root logger option
|
||||
log4j.rootLogger=TRACE, stdout, FILE
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Target=System.out
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd'T'HH:mm:ss.SSS} %-5p [%c] - %m%n
|
||||
|
||||
# Direct log messages to a log file
|
||||
# Define the File appender
|
||||
log4j.appender.FILE=org.apache.log4j.FileAppender
|
||||
|
||||
# Set the name of the file
|
||||
log4j.appender.FILE.File=MFF_LOG.txt
|
||||
|
||||
# Set the immediate flush to true (default)
|
||||
log4j.appender.FILE.ImmediateFlush=true
|
||||
|
||||
# Set the threshold to debug mode
|
||||
log4j.appender.FILE.Threshold=debug
|
||||
|
||||
# Set the append to false, overwrite
|
||||
log4j.appender.FILE.Append=true
|
||||
|
||||
# Define the layout for file appender
|
||||
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.FILE.layout.conversionPattern=%d{yyyy-MM-dd'T'HH:mm:ss.SSS} %-5p [%c] - %m%n
|
||||
|
||||
# exclude http DEBUG
|
||||
log4j.logger.org.apache.commons.httpclient=WARN, stdout
|
||||
log4j.logger.org.apache.http.*=WARN, stdout
|
||||
log4j.logger.org.apache.http=WARN, stdout
|
||||
log4j.logger.org.apache.http*=WARN, stdout
|
||||
log4j.additivity.org.apache.http.*=false
|
||||
|
||||
# only log messages
|
||||
log4j.logger.Modules.SlowMode=DEBUG, FILE2
|
||||
log4j.appender.FILE2=org.apache.log4j.FileAppender
|
||||
log4j.appender.FILE2.File=MFF_SMALL_LOG.txt
|
||||
log4j.appender.FILE2.ImmediateFlush=true
|
||||
log4j.appender.FILE2.Threshold=debug
|
||||
log4j.appender.FILE2.Append=true
|
||||
log4j.appender.FILE2.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.FILE2.layout.conversionPattern=%d{yyyy-MM-dd'T'HH:mm:ss.SSS} %-5p [%c] - %m%n
|
||||
|
7
src/main/resources/whitelist.json
Normal file
7
src/main/resources/whitelist.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
[
|
||||
{
|
||||
"role": "Admin",
|
||||
"user_name": "Hiajen",
|
||||
"id": 187200447
|
||||
}
|
||||
]
|
Loading…
Reference in a new issue