Skip to content

Commit

Permalink
style: 🎨 update clang-format; reformat all files
Browse files Browse the repository at this point in the history
  • Loading branch information
Xminent committed Dec 10, 2023
1 parent 756a6cd commit d0faa4c
Show file tree
Hide file tree
Showing 213 changed files with 1,921 additions and 2,893 deletions.
121 changes: 11 additions & 110 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,113 +1,14 @@
---
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
BasedOnStyle: Google
IndentWidth: 4
ColumnLimit: 80
CommentPragmas: "^ IWYU pragma:"
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 8
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false

ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH

IncludeBlocks: Preserve
IncludeCategories:
- Regex: ".*"
Priority: 1
IncludeIsMainRegex: "(Test)?$"
IndentCaseLabels: false
IndentGotoLabels: false
IndentPPDirectives: None
IndentWidth: 8
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ""
MacroBlockEnd: ""
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 8
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true

# Taken from git's rules
PenaltyBreakAssignment: 10
PenaltyBreakBeforeFirstCallParameter: 30
PenaltyBreakComment: 10
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 10
PenaltyExcessCharacter: 100
PenaltyReturnTypeOnItsOwnLine: 60

PointerAlignment: Right
ReflowComments: false
TabWidth: 4
UseTab: Always
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AllowShortBlocksOnASingleLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortLambdasOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatementsExceptForEachMacros
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp03
TabWidth: 8
UseTab: Always
PenaltyIndentedWhitespace: 1
132 changes: 50 additions & 82 deletions examples/simple_with_logging.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include <dotenv/dotenv.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>

#include <ekizu/embed_builder.hpp>
#include <ekizu/http_client.hpp>
#include <ekizu/shard.hpp>
#include <nlohmann/json.hpp>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>

using namespace ekizu;

const std::shared_ptr<spdlog::logger> &get_logger()
{
const std::shared_ptr<spdlog::logger> &get_logger() {
static const auto ret = [] {
auto logger = spdlog::stdout_color_mt("logger");
spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%l%$] %v");
Expand All @@ -21,16 +21,17 @@ const std::shared_ptr<spdlog::logger> &get_logger()
return ret;
}

template <typename... Func> struct overload : Func... {
template <typename... Func>
struct overload : Func... {
using Func::operator()...;
};

template <typename... Func> overload(Func...) -> overload<Func...>;
template <typename... Func>
overload(Func...) -> overload<Func...>;

std::function<void(Event)> handle_event(HttpClient &http);

int main()
{
int main() {
dotenv::init();

const auto token = dotenv::getenv("DISCORD_TOKEN");
Expand All @@ -40,19 +41,17 @@ int main()
return 1;
}

auto http = HttpClient{ token };
auto http = HttpClient{token};
const auto intents = Intents::AllIntents;
auto shard = Shard{ ShardId::ONE, token, intents };
auto shard = Shard{ShardId::ONE, token, intents};

if (const auto res = shard.run(handle_event(http)); !res) {
get_logger()->error("Failed to run shard: {}",
res.error().message());
get_logger()->error("Failed to run shard: {}", res.error().message());
return 1;
}
}

std::function<void(Event)> handle_event(HttpClient &http)
{
std::function<void(Event)> handle_event(HttpClient &http) {
return [&http, bot_id = Snowflake{}](Event ev) mutable {
const auto &logger = get_logger();

Expand All @@ -61,110 +60,79 @@ std::function<void(Event)> handle_event(HttpClient &http)
[&logger, &bot_id](const Ready &payload) {
const auto &user = payload.user;

logger->info("Logged in as {}",
user.username);
logger->info("Logged in as {}", user.username);
bot_id = user.id;

logger->info("API version: {}",
payload.v);
logger->info("Guilds: {}",
payload.guilds.size());
logger->info("API version: {}", payload.v);
logger->info("Guilds: {}", payload.guilds.size());

logger->info("Ready object: {}",
nlohmann::json{ payload }
.dump());
logger->info(
"Ready object: {}", nlohmann::json{payload}.dump());
},
[&logger, &http,
&bot_id](const MessageCreate &payload) {
[&logger, &http, &bot_id](const MessageCreate &payload) {
const auto &[msg] = payload;

if (msg.author.id == bot_id) {
return;
}
if (msg.author.id == bot_id) { return; }

logger->info("Message: {}",
msg.content);
logger->info("Message: {}", msg.content);

const auto embed =
EmbedBuilder{}
.add_field(EmbedField{
"message",
msg.content,
false })
.add_field(
EmbedField{"message", msg.content, false})
.set_author({
msg.author
.username,
msg.author.username,
{},
"https://thicc.mywaifulist.moe/waifus/3/f64620cfa45bcab439a9d4b1990c550801a97dc65b55cbc76c0c947a2b139443_thumb.jpg",
"https://thicc.mywaifulist.moe/waifus/3/"
"f64620cfa45bcab439a9d4b1990c550801a97dc65b55cb"
"c76c0c947a2b139443_thumb.jpg",
})
.set_footer(
{ "Generated by: ekizu with C++",
"https://thicc.mywaifulist.moe/waifus/2719/5ab850fd407af23507f85ea0b09c1dae6c9f1534ee1ef6ba4649a3dc2f603552_thumb.jpg" })
.set_image(
{ "https://avatars.githubusercontent.com/u/59069386?v=4" })
{"Generated by: ekizu with C++",
"https://thicc.mywaifulist.moe/waifus/2719/"
"5ab850fd407af23507f85ea0b09c1dae6c9f1534ee1ef"
"6ba4649a3dc2f603552_thumb.jpg"})
.set_image({"https://avatars.githubusercontent.com/"
"u/59069386?v=4"})
.build();

http.create_message(msg.channel_id)
.content(fmt::format(
"{} said: {}\nAvatar: {}",
msg.author.username,
"{} said: {}\nAvatar: {}", msg.author.username,
msg.content,
msg.author.avatar ?
*msg.author
.avatar :
"null"))
.embeds({ embed })
msg.author.avatar ? *msg.author.avatar : "null"))
.embeds({embed})
.send()
.map([&logger](
const auto
&new_msg) {
logger->info(
"Sent message: {}",
new_msg.id);
.map([&logger](const auto &new_msg) {
logger->info("Sent message: {}", new_msg.id);
})
.map_error([&logger](
const auto &
err) {
.map_error([&logger](const auto &err) {
logger->error(
"Failed to send message: {}",
err.message());
"Failed to send message: {}", err.message());
});

if (msg.content == "delete me") {
http.delete_message(
msg.channel_id,
msg.id)
http.delete_message(msg.channel_id, msg.id)
.send()
.map([&logger,
msg_id = msg.id](
const auto &
res) {
.map([&logger, msg_id = msg.id](const auto &res) {
if (res.status_code ==
net::HttpStatus::
NoContent) {
logger->info(
"Deleted message: {}",
msg_id);
net::HttpStatus::NoContent) {
logger->info("Deleted message: {}", msg_id);
}
})
.map_error([&logger](
const auto
&err) {
logger->error(
"Failed to delete message: {}",
err.message());
.map_error([&logger](const auto &err) {
logger->error("Failed to delete message: {}",
err.message());
});
}
},
[&logger](const Log &log) {
logger->debug("Log: {}", log.message);
},
[&logger](const auto &e) {
logger->info(
"Uncaught {} event: {}",
typeid(e).name(),
nlohmann::json{ e }.dump());
} },
logger->info("Uncaught {} event: {}", typeid(e).name(),
nlohmann::json{e}.dump());
}},
ev);
};
}
13 changes: 5 additions & 8 deletions include/ekizu/activity_flags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#include <cstdint>
#include <type_traits>

namespace ekizu
{
namespace ekizu {
enum class ActivityFlags : uint64_t {
Instance = 1 << 0,
Join = 1 << 1,
Expand All @@ -18,19 +17,17 @@ enum class ActivityFlags : uint64_t {
Embedded = 1 << 8,
};

constexpr ActivityFlags operator|(ActivityFlags lhs, ActivityFlags rhs)
{
constexpr ActivityFlags operator|(ActivityFlags lhs, ActivityFlags rhs) {
return static_cast<ActivityFlags>(
static_cast<std::underlying_type_t<ActivityFlags> >(lhs) |
static_cast<std::underlying_type_t<ActivityFlags> >(rhs));
}

constexpr ActivityFlags operator&(ActivityFlags lhs, ActivityFlags rhs)
{
constexpr ActivityFlags operator&(ActivityFlags lhs, ActivityFlags rhs) {
return static_cast<ActivityFlags>(
static_cast<std::underlying_type_t<ActivityFlags> >(lhs) &
static_cast<std::underlying_type_t<ActivityFlags> >(rhs));
}
} // namespace ekizu
} // namespace ekizu

#endif // EKIZU_ACTIVITY_FLAGS_HPP
#endif // EKIZU_ACTIVITY_FLAGS_HPP
Loading

0 comments on commit d0faa4c

Please sign in to comment.