Skip to content

Commit

Permalink
Remove Twitter integration
Browse files Browse the repository at this point in the history
Completely removes all references to Twittter integration and tweepy, as Twitter is no longer a functioning website.

Resolves #218
  • Loading branch information
super-cooper committed Nov 17, 2024
1 parent 572dfc6 commit b7d9fbe
Show file tree
Hide file tree
Showing 14 changed files with 7 additions and 635 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ venv.bak/
# project specific
client_token
data/
twitter_api_tokens.json
.vscode/
.env

12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,19 @@ See [Configuration](#configuration) for more context.

```
usage: main.py [-h] [--discord-api-token DISCORD_API_TOKEN]
[--twitter-api-consumer-key TWITTER_API_CONSUMER_KEY]
[--twitter-api-consumer-secret TWITTER_API_CONSUMER_SECRET]
[--twitter-api-bearer-token TWITTER_API_BEARER_TOKEN]
[--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL} | -v]
[--log-location {stdout,stderr,syslog,/path/to/file}]
[--no-twitter] [--nodb] [--database-uri DATABASE_URI]
[--nodb] [--database-uri DATABASE_URI]
optional arguments:
-h, --help show this help message and exit
--discord-api-token DISCORD_API_TOKEN
The Discord API client token
--twitter-api-consumer-key TWITTER_API_CONSUMER_KEY
(DEPRECATED) The Twitter API consumer key
--twitter-api-consumer-secret TWITTER_API_CONSUMER_SECRET
(DEPRECATED) The Twitter API consumer secret
--twitter-api-bearer-token TWITTER_API_BEARER_TOKEN
The Twitter API OAuth 2.0 bearer token
--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
Set logging level
-v, --verbose Use verbose logging. Equivalent to --log-level DEBUG
--log-location {stdout,stderr,syslog,/path/to/file}
Set the location for MemeBot's log
--no-twitter Disable Twitter integration
--nodb Disable the database connection, and all features
which require it.
--database-uri DATABASE_URI
Expand Down
7 changes: 0 additions & 7 deletions docker/template.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# API Tokens
# MEMEBOT_DISCORD_CLIENT_TOKEN=
# MEMEBOT_TWITTER_BEARER_TOKEN=

# Network configuration
# MEMEBOT_NETWORK_SUBNET=
# MEMEBOT_NETWORK_DNS_SERVER=
Expand All @@ -12,9 +8,6 @@
# MEMEBOT_IMAGE_NAME=
# MEMEBOT_BUILD_TARGET=

# Integration settings
# MEMEBOT_TWITTER_ENABLED=

# Logging settings
# MEMEBOT_LOG_LEVEL=
# MEMEBOT_LOG_LOCATION=
Expand Down
5 changes: 0 additions & 5 deletions memebot/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from memebot import config
from memebot import db
from memebot import log
from memebot.integrations import twitter
from memebot.lib import exception, util


Expand All @@ -22,8 +21,6 @@ async def on_ready() -> None:
log.info(f"Logged in as {memebot.user}")
synced = await memebot.tree.sync()
log.info(f"Synced {len(synced)} command(s)")
if config.twitter_enabled:
twitter.init(memebot.user)
if config.database_enabled:
db_online = db.test()
if db_online:
Expand Down Expand Up @@ -101,7 +98,5 @@ def get_memebot() -> discord.ext.commands.Bot:
new_memebot.add_listener(on_ready)
new_memebot.add_listener(on_interaction)
new_memebot.tree.error(on_command_error)
if config.twitter_enabled:
new_memebot.add_listener(twitter.process_message_for_interaction, "on_message")

return new_memebot
47 changes: 0 additions & 47 deletions memebot/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@

# Discord API token
discord_api_token: str
# Twitter API tokens
twitter_api_bearer_token: str

# The logging level for MemeBot
log_level: str
# The location for MemeBot's log
log_location: logging.Handler

# Flag which tells if Twitter integration is enabled
twitter_enabled: bool

# Flag which tells if a database connection is enabled
database_enabled: bool
# MongoDB URI
Expand All @@ -34,30 +29,6 @@ def populate_config_from_command_line() -> None:
default=os.getenv("MEMEBOT_DISCORD_CLIENT_TOKEN"),
type=str,
)
parser.add_argument(
"--twitter-api-consumer-key",
help="(DEPRECATED) The Twitter API consumer key",
default=os.getenv("MEMEBOT_TWITTER_CONSUMER_KEY"),
type=lambda _: print(
"USING DEPRECATED TWITTER OAUTH 1.0 CREDENTIALS! "
"PLEASE USE BEARER TOKENS INSTEAD!"
),
)
parser.add_argument(
"--twitter-api-consumer-secret",
help="(DEPRECATED) The Twitter API consumer secret",
default=os.getenv("MEMEBOT_TWITTER_CONSUMER_SECRET"),
type=lambda _: print(
"USING DEPRECATED TWITTER OAUTH 1.0 CREDENTIALS! "
"PLEASE USE BEARER TOKENS INSTEAD!"
),
)
parser.add_argument(
"--twitter-api-bearer-token",
help="The Twitter API OAuth 2.0 bearer token",
default=os.getenv("MEMEBOT_TWITTER_BEARER_TOKEN"),
type=str,
)

# Logging Configuration
logging_verbosity_group = parser.add_mutually_exclusive_group()
Expand Down Expand Up @@ -94,19 +65,6 @@ def populate_config_from_command_line() -> None:
type=validators.validate_log_location,
)

# Twitter Integration
parser.add_argument(
"--no-twitter",
help="Disable Twitter integration",
dest="twitter_enabled",
action="store_false",
)
parser.set_defaults(
twitter_enabled=validators.validate_bool(
os.getenv("MEMEBOT_TWITTER_ENABLED", str(True))
)
)

# Database Configuration
parser.add_argument(
"--nodb",
Expand All @@ -132,18 +90,13 @@ def populate_config_from_command_line() -> None:
args = parser.parse_args()

global discord_api_token
global twitter_api_bearer_token
discord_api_token = args.discord_api_token
twitter_api_bearer_token = args.twitter_api_bearer_token

global log_level
global log_location
log_level = args.log_level
log_location = args.log_location

global twitter_enabled
twitter_enabled = args.twitter_enabled

global database_enabled
global database_uri
database_enabled = args.database_enabled
Expand Down
181 changes: 0 additions & 181 deletions memebot/integrations/twitter.py

This file was deleted.

12 changes: 0 additions & 12 deletions memebot/log/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@
atexit.register(logging.shutdown)


def set_third_party_logging() -> None:
"""
Enable logging on third-party packages that can't be overwritten with MemeBotLogger
"""
# Tweepy does not use a unified logger, so the best we can do is
# enable its debug mode.
import asyncio

if config.log_level == logging.getLevelName(logging.DEBUG):
asyncio.get_event_loop().set_debug(True)


# Forward memebot_logger's logging methods as module-level functions
debug = memebot_logger.debug
info = memebot_logger.info
Expand Down
5 changes: 4 additions & 1 deletion memebot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ def main() -> None:
Main function, initializes MemeBot and then loops
:return: Exit status of discord.Client.run()
"""
log.set_third_party_logging()
config.populate_config_from_command_line()
# the ``log`` package should be imported ASAP to ensure our logging shims
# are injected into the runtime before external packages configure
# their logging
log.info("Starting up memebot!")
memebot = get_memebot()

# !! DO NOT HARDCODE THE TOKEN !!
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ exclude = [

[[tool.mypy.overrides]]
module = [
# tweepy does not provide type annotations, but it is desired for 4.x
"tweepy",
# This module in discord.py does not have full stubs for some reason
"discord.ext.commands",
]
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ discord.py~=2.1.0
emoji~=2.0.0
pymongo~=3.13.0
pymongo-stubs~=0.2.0
tweepy~=4.12.0
types-emoji~=2.0.0
Loading

0 comments on commit b7d9fbe

Please sign in to comment.