Skip to content

Commit

Permalink
Merge pull request #7 from NotYourAverageGamer/v3.1.0
Browse files Browse the repository at this point in the history
V3.1.0
  • Loading branch information
NotYourAverageGamer authored Jun 12, 2024
2 parents a0ecb23 + c976ece commit dd5e623
Show file tree
Hide file tree
Showing 15 changed files with 198 additions and 79 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# AscensionChat

AscensionChat is a Discord integration chat bot for the **Ascension Project**, forked from **WoWChat** by fjaros. My _(NotYourAverageGamer)_ fork also contains code sourced from **szyler** and **xan-asc** — thank you all!
AscensionChat is a Discord integration chat bot for **Project Ascension**, originally forked from **WoWChat** by fjaros. My _(NotYourAverageGamer)_ fork also contains code sourced from **szyler** and **xan-asc** — thank you all!

**Note:** This fork has been modified for use with the Ascension Project. While the code is still technically there, changes will need to be made if you want to use this with other servers _(perhaps take a look at one of the forks mentioned above, which should provide a better starting point)_. It does NOT support WoW Classic or Retail servers.

**New Requirement:** Due to Discord changes, you must check `PRESENCE INTENT` and `SERVER MEMBERS INTENT` under the `Privileged Gateway Intents` section in the Discord developer portal.
**New Requirement:** Due to Discord changes, you must check `PRESENCE INTENT`, `SERVER MEMBERS INTENT` AND `MESSAGE CONTENT INTENT` under the `Privileged Gateway Intents` section in the Discord developer portal.

Currently supported version of this fork:

Expand Down Expand Up @@ -51,8 +51,8 @@ Even though this bot does not do anything malicious, some servers may not like a
- On the left, click the `Bot` tab
- Add a Bot
- Disable the `Public Bot` option
- Enable `PRESENCE INTENT` and `SERVER MEMBERS INTENT` under `Privileged Gateway Intents`. **This is important! Without it, your bot will not work!**
- Underneath where it says `TOKEN`, click `Copy`. This is what Ascension Chat will use to log into Discord.
- Enable `PRESENCE INTENT`, `SERVER MEMBERS INTENT` and `MESSAGE CONTENT INTENT` under `Privileged Gateway Intents`. **This is important! Without it, your bot will not work!**
- Underneath where it says `TOKEN`, click `Copy`. _(If you can't see a copy option, click reset then copy)_ This is what Ascension Chat will use to log into Discord.
2. Configure AscensionChat by opening `ascensionchat.conf` in your text editor of choice. You can also create your own file using the supplied `ascensionchat.conf` as a template.

- **Discord** section:
Expand Down Expand Up @@ -133,8 +133,8 @@ Even though this bot does not do anything malicious, some servers may not like a

- You may need to restart your terminal for the install/upgrade to take effect.

3. Run `mvn clean package` which will produce a file in the target folder called `ascensionchat-24.6.3.zip`
4. Unzip `ascensionchat-24.6.3.zip`, edit the configuration file, and run `run.bat` for Windows or `run.sh` for Linux/MacOS. (Edit the name of the config file in `run.*` if you supply your own config)
3. Run `mvn clean package` which will produce a file in the target folder called `ascensionchat-3.1.0.zip`
4. Unzip `ascensionchat-3.1.0.zip`, edit the configuration file, and run `run.bat` for Windows or `run.sh` for Linux/MacOS. (Edit the name of the config file in `run.*` if you supply your own config)
- If no config file is supplied, the bot will try to use `ascensionchat.conf`

## Updating
Expand Down
11 changes: 9 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

<groupId>ascensionchat</groupId>
<artifactId>ascensionchat</artifactId>
<version>24.6.3</version>
<version>3.1.0</version>

<properties>
<java.version>1.8</java.version>
<scala.version.major>2.12</scala.version.major>
<scala.version.minor>19</scala.version.minor>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
Expand All @@ -31,7 +32,7 @@
<dependency>
<groupId>com.typesafe.scala-logging</groupId>
<artifactId>scala-logging_${scala.version.major}</artifactId>
<version>3.9.4</version>
<version>3.9.5</version>
</dependency>

<!-- config -->
Expand Down Expand Up @@ -67,6 +68,12 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/ascensionchat.conf
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ wow {
version=3.3.5
realmlist=162.19.28.88
realm=Area 52 - Free-pick
# Quotation marks are used otherwise we can get errors, particularly with complex (secure) passwords
# Quotation marks are used otherwise we can get errors, particularly with complex/secure passwords
account=REPLACE-ME
password="REPLACE-ME"
character=REPLACE-ME
Expand All @@ -65,6 +65,8 @@ wow {
# Guild notifications. ('enabled=0' = disbaled | 'enabled=1' = enabled)
# Using the 'channel' option is not required. You can use Channel ID or Channel name. Channel ID is preferred, but not required.
# Using the Channel ID allows you to rename the channel without having to change the name in this config file.
# IF CHANNEL_NAME USE: channel="example-channel"
# IF CHANNEL_ID USE: channel=123456
guild {
online {
enabled=0
Expand Down
17 changes: 15 additions & 2 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@
<!-- Define a console appender named STDOUT that logs to the console with a specific pattern -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-5level %logger{16} - %msg%n</pattern>
<pattern>%d{HH:mm:ss} [%highlight(%level)] - %msg%n</pattern>
<highlightingPolicy>
<defaultHighlightingPolicy>
<pattern>
<style name="INFO" foreground="bright_blue"/>
<style name="WARN" foreground="bright_yellow"/>
<style name="ERROR" foreground="bright_red"/>
</pattern>
</defaultHighlightingPolicy>
</highlightingPolicy>
</encoder>
</appender>

<!-- Set the logging level for specific loggers to INFO -->
<!-- Suppress logback initialization messages -->
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />

<!-- Set the logging level for specific loggers -->
<logger name="ch.qos.logback" level="ERROR" />
<logger name="net.dv8tion.jda.core.requests.Requester" level="INFO" />

<logger name="wowchat.game.GamePacketEncoder" level="INFO" />
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
release.version=v${project.version}
62 changes: 62 additions & 0 deletions src/main/scala/wowchat/Ansi.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* This file holds the colours I used for the logo etc (and more)
I figured out later that Scala has 'AnsiColor' in their library, LOL.
I like this as a reference anyway. Plus, you can edit the values for them as you please. */

package wowchat

object Ansi {
// ANSI escape codes for normal colours
val GREY = "\u001b[30m"
val RED = "\u001B[31m"
val GREEN = "\u001B[32m"
val YELLOW = "\u001B[33m"
val BLUE = "\u001B[34m"
val PURPLE = "\u001B[35m"
val CYAN = "\u001B[36m"
val WHITE = "\u001B[37m"

// ANSI escape codes for bright colours
val BGREY = "\u001B[90m"
val BRED = "\u001B[91m"
val BGREEN = "\u001B[92m"
val BYELLOW = "\u001B[93m"
val BBLUE = "\u001B[94m"
val BPURPLE = "\u001B[95m"
val BCYAN = "\u001B[96m"
val BWHITE = "\u001B[97m"

// ANSI escape code to reset all styles
val CLR = "\u001B[0m"

// ANSI escape codes for background colours
val BLACK_BG = "\u001B[40m"
val RED_BG = "\u001B[41m"
val GREEN_BG = "\u001B[42m"
val YELLOW_BG = "\u001B[43m"
val BLUE_BG = "\u001B[44m"
val PURPLE_BG = "\u001B[45m"
val CYAN_BG = "\u001B[46m"
val WHITE_BG = "\u001B[47m"

// ANSI escape codes for bright background colours
val BBLACK_BG = "\u001B[100m"
val BRED_BG = "\u001B[101m"
val BGREEN_BG = "\u001B[102m"
val BYELLOW_BG = "\u001B[103m"
val BBLUE_BG = "\u001B[104m"
val BPURPLE_BG = "\u001B[105m"
val BCYAN_BG = "\u001B[106m"
val BWHITE_BG = "\u001B[107m"

// ANSI escape codes for text styles
val BOLD = "\u001B[1m"
val FAINT = "\u001B[2m"
val ITALIC = "\u001B[3m"
val UNDERLINE = "\u001B[4m"
val BLINK = "\u001B[5m"
val RAPID_BLINK = "\u001B[6m"
val REVERSE = "\u001B[7m"
val CONCEAL = "\u001B[8m"
val STRIKE_THROUGH = "\u001B[9m"

}
47 changes: 34 additions & 13 deletions src/main/scala/wowchat/WoWChat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,34 @@ import wowchat.common.{CommonConnectionCallback, Global, ReconnectDelay, WowChat
import wowchat.discord.Discord
import wowchat.game.GameConnector
import wowchat.realm.{RealmConnectionCallback, RealmConnector}

import com.typesafe.scalalogging.StrictLogging
import io.netty.channel.nio.NioEventLoopGroup

import scala.io.Source

object WoWChat extends StrictLogging {

private val RELEASE = "v24.6.3"
private val RELEASE = Source.fromResource("version.properties").getLines.next().split("=")(1).trim

/** Main entry point of the application. */
def main(args: Array[String]): Unit = {
logger.info(s"Running AscensionChat - $RELEASE")
// Determine the configuration file path.
logger.info(s"""${Ansi.BOLD}


${Ansi.GREEN} .d8b. .d8888. .o88b. d88888b d8b db .d8888. d888888b .d88b. d8b db .o88b. db db .d8b. d888888b
${Ansi.GREEN} d8' `8b 88' YP d8P Y8 88' 888o 88 88' YP `88' .8P Y8. 888o 88 d8P Y8 88 88 d8' `8b `~~88~~'
${Ansi.GREEN} 88ooo88 `8bo. 8P 88ooooo 88V8o 88 `8bo. 88 88 88 88V8o 88 8P 88ooo88 88ooo88 88
${Ansi.GREEN} 88~~~88 `Y8b. 8b 88~~~~~ 88 V8o88 `Y8b. 88 88 88 88 V8o88 8b 88~~~88 88~~~88 88
${Ansi.GREEN} 88 88 db 8D Y8b d8 88. 88 V888 db 8D .88. `8b d8' 88 V888 Y8b d8 88 88 88 88 88
${Ansi.GREEN} YP YP `8888Y' `Y88P' Y88888P VP V8P `8888Y' Y888888P `Y88P' VP V8P `Y88P' YP YP YP YP YP


${Ansi.BCYAN}~~>>>${Ansi.CLR}${Ansi.BYELLOW} $RELEASE ${Ansi.BOLD}${Ansi.BCYAN}<<<~~


${Ansi.CLR}""")
// Determine the configuration file path.
val confFile = if (args.nonEmpty) {
args(0)
} else {
Expand Down Expand Up @@ -70,9 +85,9 @@ object WoWChat extends StrictLogging {
/** Initiates reconnection to the game server. */
def doReconnect: Unit = {
Global.group.shutdownGracefully()
Global.discord.changeRealmStatus("Connecting...")
Global.discord.changeRealmStatus(s"${Ansi.BCYAN}Connecting...${Ansi.CLR}")
val delay = reconnectDelay.getNext
logger.info(s"Disconnected from server! Reconnecting in $delay seconds...")
logger.info(s"${Ansi.RED}Disconnected from server!${Ansi.CLR} Reconnecting in $delay seconds...")

// Schedule reconnection after delay.
reconnectExecutor.schedule(new Runnable {
Expand All @@ -81,7 +96,7 @@ object WoWChat extends StrictLogging {
}
}

logger.info("Connecting to Discord...")
logger.info(s"${Ansi.BCYAN}Connecting to Discord...${Ansi.CLR}")
// Initialize the Discord connection.
Global.discord = new Discord(new CommonConnectionCallback {
/** Callback method on successful connection. Initiates game connection. */
Expand All @@ -104,12 +119,18 @@ object WoWChat extends StrictLogging {
.getOrElse("NOT FOUND")

// Display version comparison message if a newer version is available.
if (repoTagName != RELEASE) {
logger.error( "~~~ !!! YOUR AscensionChat VERSION IS OUT OF DATE !!! ~~~")
logger.error(s"~~~ !!! Current Version: $RELEASE !!! ~~~")
logger.error(s"~~~ !!! Latest Version: $repoTagName !!! ~~~")
logger.error( "~~~ !!! GO TO https://github.com/NotYourAverageGamer/AscensionChat TO UPDATE !!! ~~~")
logger.error( "~~~ !!! YOUR AscensionChat VERSION IS OUT OF DATE !!! ~~~")
}
if (repoTagName != RELEASE) {
logger.error(s"""${Ansi.BYELLOW}


~~~ ${Ansi.BRED} !!! ${Ansi.BCYAN}YOUR AscensionChat VERSION IS OUT OF DATE ${Ansi.BRED}!!! ${Ansi.BYELLOW} ~~~
~~~ ${Ansi.BRED} !!! ${Ansi.BYELLOW}Current Version${Ansi.BWHITE}: ${Ansi.BYELLOW}$RELEASE ${Ansi.BRED}!!! ${Ansi.BYELLOW} ~~~
~~~ ${Ansi.BRED} !!! ${Ansi.BGREEN}Latest Version${Ansi.BWHITE}: ${Ansi.BGREEN}$repoTagName ${Ansi.BRED}!!! ${Ansi.BYELLOW} ~~~
~~~ ${Ansi.BRED} !!! ${Ansi.BWHITE}GO TO ${Ansi.BOLD}${Ansi.BLUE}https://github.com/NotYourAverageGamer/AscensionChat${Ansi.CLR} ${Ansi.BWHITE}TO UPDATE ${Ansi.BRED}!!! ${Ansi.BYELLOW} ~~~
~~~ ${Ansi.BRED} !!! ${Ansi.BCYAN}YOUR AscensionChat VERSION IS OUT OF DATE ${Ansi.BRED}!!! ${Ansi.BYELLOW} ~~~

${Ansi.CLR}""")
}
}
}
8 changes: 4 additions & 4 deletions src/main/scala/wowchat/common/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ object WowChatConfig extends GamePackets {
"demoted" -> (true, "`[%user] has demoted [%target] to [%rank].`"),
"online" -> (false, "`[%user] has come online.`"),
"offline" -> (false, "`[%user] has gone offline.`"),
"joined" -> (true, "`[%user] has joined the guild.`"),
"left" -> (true, "`[%user] has left the guild.`"),
"removed" -> (true, "`[%target] has been kicked out of the guild by [%user].`"),
"motd" -> (true, "`Guild Message of the Day: %message`"),
"joined" -> (true, "` + [%user] has joined the guild.`"),
"left" -> (true, "` - [%user] has left the guild.`"),
"removed" -> (true, "` - [%target] has been kicked out of the guild by [%user].`"),
"motd" -> (true, "```Guild Message of the Day: %message```"),
"achievement" -> (true, "%user has earned the achievement %achievement!")
)

Expand Down
18 changes: 10 additions & 8 deletions src/main/scala/wowchat/discord/Discord.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package wowchat.discord

import wowchat.commands.CommandHandler
import wowchat.common._
import wowchat.Ansi

import com.typesafe.scalalogging.StrictLogging
import com.vdurmont.emoji.EmojiParser
import net.dv8tion.jda.api.JDABuilder
Expand Down Expand Up @@ -123,7 +125,7 @@ class Discord(discordConnectionCallback: CommonConnectionCallback) extends Liste
.replace("%target", wowChannel.getOrElse(""))

val filter = shouldFilter(channelConfig.filters, formatted)
logger.info(s"${if (filter) "FILTERED " else ""}WoW->Discord(${channel.getName}) $formatted")
logger.info(s"${if (filter) "FILTERED " else ""}WoW->Discord (${channel.getName}): $formatted")
if (!filter) {
channel.sendMessage(formatted).queue()
}
Expand Down Expand Up @@ -152,7 +154,7 @@ class Discord(discordConnectionCallback: CommonConnectionCallback) extends Liste
).map(_._1)
)
.foreach(channel => { // TODO: Add a line with "check if variable enabled"
logger.info(s"WoW->Discord(${channel.getName}) $message")
logger.info(s"WoW->Discord (${channel.getName}): $message")
channel.sendMessage(message).queue()
})
}
Expand Down Expand Up @@ -240,7 +242,7 @@ class Discord(discordConnectionCallback: CommonConnectionCallback) extends Liste
}
.foreach {
case (key, _) =>
logger.info(s"Adding Binding ($key -> ${channel.getName})")
logger.info(s"${Ansi.BCYAN}Adding Binding ${Ansi.CLR}($key -> ${channel.getName})")
Global.guildEventsToDiscord.addBinding(key, channel)
}
})
Expand All @@ -253,7 +255,7 @@ class Discord(discordConnectionCallback: CommonConnectionCallback) extends Liste
discordConnectionCallback.reconnected
}
} else {
logger.error("No discord channels configured!")
logger.error(s"${Ansi.BRED}No discord channels configured!${Ansi.CLR}")
}
case Status.DISCONNECTED =>
discordConnectionCallback.disconnected
Expand All @@ -264,7 +266,7 @@ class Discord(discordConnectionCallback: CommonConnectionCallback) extends Liste
override def onShutdown(event: ShutdownEvent): Unit = {
event.getCloseCode match {
case CloseCode.DISALLOWED_INTENTS =>
logger.error("Per new Discord rules, you must check the PRESENCE INTENT and SERVER MEMBERS INTENT boxes under \"Privileged Gateway Intents\" for this bot in the developer portal. You can find more info at https://discord.com/developers/docs/topics/gateway#privileged-intents")
logger.error(s"${Ansi.BRED}Per new Discord rules, you must check the ${Ansi.BOLD}PRESENCE INTENT ${Ansi.CLR}and ${Ansi.BOLD}SERVER MEMBERS INTENT ${Ansi.CLR}boxes under ${Ansi.BOLD}Privileged Gateway Intents ${Ansi.CLR}in the developer portal for this bot to work. You can find more info at${Ansi.CLR} https://discord.com/developers/docs/topics/gateway#privileged-intents")
case _ =>
}
}
Expand Down Expand Up @@ -310,11 +312,11 @@ class Discord(discordConnectionCallback: CommonConnectionCallback) extends Liste

finalMessages.foreach(finalMessage => {
val filter = shouldFilter(channelConfig.filters, finalMessage)
logger.info(s"${if (filter) "FILTERED " else ""}Discord->WoW(${
logger.info(s"${if (filter) "FILTERED " else ""}Discord->WoW (${
channelConfig.channel.getOrElse(ChatEvents.valueOf(channelConfig.tp))
}) $finalMessage")
}): $finalMessage")
if (!filter) {
Global.game.fold(logger.error("Cannot send message! Not connected to WoW!"))(handler => {
Global.game.fold(logger.error(s"${Ansi.BRED}Cannot send message! Not connected to WoW!${Ansi.CLR}"))(handler => {
handler.sendMessageToWow(channelConfig.tp, finalMessage, channelConfig.channel)
})
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/scala/wowchat/game/GameConnector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import java.net.InetSocketAddress
import java.util.concurrent.TimeUnit

import wowchat.common._
import wowchat.Ansi

import com.typesafe.scalalogging.StrictLogging
import io.netty.bootstrap.Bootstrap
import io.netty.channel.{Channel, ChannelInitializer, ChannelOption}
Expand Down Expand Up @@ -44,11 +46,11 @@ class GameConnector(host: String,
*/
def connect: Unit = {
if (channel.fold(false)(_.isActive)) {
logger.error("Refusing to connect to game server. Connection already exists.")
logger.error(s"${Ansi.BYELLOW}Refusing to connect to game server. Connection already exists.${Ansi.CLR}")
return
}

logger.info(s"Connecting to game server $realmName ($host:$port)")
logger.info(s"${Ansi.BCYAN}Connecting to game server${Ansi.BPURPLE} $realmName ($host:$port)${Ansi.CLR}")

val bootstrap = new Bootstrap
bootstrap.group(Global.group)
Expand Down Expand Up @@ -106,7 +108,7 @@ class GameConnector(host: String,
Try {
future.get(10, TimeUnit.SECONDS)
}.fold(throwable => {
logger.error(s"Failed to connect to game server! ${throwable.getMessage}")
logger.error(s"${Ansi.BRED}Failed to connect to game server! ${Ansi.CLR}${throwable.getMessage}")
gameEventCallback.disconnected
}, _ => Unit)
}).channel)
Expand Down
Loading

0 comments on commit dd5e623

Please sign in to comment.